Skip to content

Commit

Permalink
[CodeHealth] Apply performance-move-const-arg (#26497)
Browse files Browse the repository at this point in the history
This check has detected a few places where the use of `std::move` has
been completely misleading. In one of them we are potentially incurring
in a bug, as we are moving a shared callback that is being used in a
loop.

https://clang.llvm.org/extra/clang-tidy/checks/performance/move-const-arg.html

Resolves brave/brave-browser#42230
  • Loading branch information
cdesouza-chromium authored Nov 12, 2024
1 parent d0becfc commit 4ffbda2
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void AdBlockFiltersProviderManager::LoadFilterSetForEngine(
auto& filters_providers = is_for_default_engine
? default_engine_filters_providers_
: additional_engine_filters_providers_;
const auto collect_and_merge = base::BarrierCallback<
auto collect_and_merge = base::BarrierCallback<
base::OnceCallback<void(rust::Box<adblock::FilterSet>*)>>(
filters_providers.size(),
base::BindOnce(&AdBlockFiltersProviderManager::FinishCombinating,
Expand All @@ -89,7 +89,7 @@ void AdBlockFiltersProviderManager::LoadFilterSetForEngine(
task_tracker_.PostTask(
base::SequencedTaskRunner::GetCurrentDefault().get(), FROM_HERE,
base::BindOnce(&AdBlockFiltersProvider::LoadFilterSet,
provider->AsWeakPtr(), std::move(collect_and_merge)));
provider->AsWeakPtr(), collect_and_merge));
}
}

Expand Down
3 changes: 1 addition & 2 deletions components/debounce/core/browser/debounce_rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ DebounceRule::ParseRules(const std::string& contents) {
}
for (const URLPattern& pattern : rule->include_pattern_set()) {
if (!pattern.host().empty()) {
const std::string etldp1 =
DebounceRule::GetETLDForDebounce(pattern.host());
std::string etldp1 = DebounceRule::GetETLDForDebounce(pattern.host());
if (!etldp1.empty()) {
hosts.insert(std::move(etldp1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void HttpsUpgradeExceptionsService::OnDATFileDataReady(
}
std::vector<std::string> lines = base::SplitString(
contents, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
for (const auto& line : lines) {
for (auto&& line : lines) {
exceptional_domains_.insert(std::move(line));
}
is_ready_ = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void LocalhostPermissionComponent::OnDATFileDataReady(
continue;
}
// Construct a GURL from the line, and store the eTLD+1.
const auto url = GURL("https://" + std::move(line));
const auto url = GURL("https://" + line);
if (url.is_valid()) {
allowed_domains_.insert(GetDomain(url));
}
Expand Down
8 changes: 4 additions & 4 deletions components/p3a/p3a_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,23 @@ P3AConfig P3AConfig::LoadFromCommandLine() {

config.average_upload_interval = MaybeOverrideTimeDeltaFromCommandLine(
cmdline, switches::kP3AUploadIntervalSeconds,
std::move(config.average_upload_interval));
config.average_upload_interval);

config.randomize_upload_interval =
!cmdline->HasSwitch(switches::kP3ADoNotRandomizeUploadInterval);

config.json_rotation_intervals[MetricLogType::kSlow] =
MaybeOverrideTimeDeltaFromCommandLine(
cmdline, switches::kP3ASlowRotationIntervalSeconds,
std::move(config.json_rotation_intervals[MetricLogType::kSlow]));
config.json_rotation_intervals[MetricLogType::kSlow]);
config.json_rotation_intervals[MetricLogType::kTypical] =
MaybeOverrideTimeDeltaFromCommandLine(
cmdline, switches::kP3ATypicalRotationIntervalSeconds,
std::move(config.json_rotation_intervals[MetricLogType::kTypical]));
config.json_rotation_intervals[MetricLogType::kTypical]);
config.json_rotation_intervals[MetricLogType::kExpress] =
MaybeOverrideTimeDeltaFromCommandLine(
cmdline, switches::kP3AExpressRotationIntervalSeconds,
std::move(config.json_rotation_intervals[MetricLogType::kExpress]));
config.json_rotation_intervals[MetricLogType::kExpress]);

config.fake_star_epochs[MetricLogType::kSlow] =
MaybeSetUint8FromCommandLine(cmdline, switches::kP3AFakeSlowStarEpoch);
Expand Down
2 changes: 1 addition & 1 deletion components/permissions/permission_lifetime_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace permissions {
PermissionLifetimeOption::PermissionLifetimeOption(
std::u16string label,
std::optional<base::TimeDelta> lifetime)
: label(std::move(label)), lifetime(std::move(lifetime)) {}
: label(std::move(label)), lifetime(lifetime) {}

PermissionLifetimeOption::PermissionLifetimeOption(
const PermissionLifetimeOption&) = default;
Expand Down
2 changes: 1 addition & 1 deletion components/request_otr/browser/request_otr_rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ RequestOTRRule::ParseRules(const std::string& contents) {
}
for (const URLPattern& pattern : rule->include_pattern_set()) {
if (!pattern.host().empty()) {
const std::string etldp1 =
std::string etldp1 =
RequestOTRRule::GetETLDForRequestOTR(pattern.host());
if (!etldp1.empty()) {
hosts.insert(std::move(etldp1));
Expand Down
2 changes: 1 addition & 1 deletion components/tor/tor_file_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ constexpr char kControlAuthCookieName[] = "control_auth_cookie";
constexpr char kControlPortName[] = "controlport";
} // namespace

TorFileWatcher::TorFileWatcher(const base::FilePath& watch_dir_path)
TorFileWatcher::TorFileWatcher(base::FilePath watch_dir_path)
: polling_(false),
repoll_(false),
watch_dir_path_(std::move(watch_dir_path)),
Expand Down
2 changes: 1 addition & 1 deletion components/tor/tor_file_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TorFileWatcher {
using WatchCallback = base::OnceCallback<
void(bool success, std::vector<uint8_t> cookie, int port)>;

explicit TorFileWatcher(const base::FilePath& watch_dir_path);
explicit TorFileWatcher(base::FilePath watch_dir_path);

~TorFileWatcher();

Expand Down

0 comments on commit 4ffbda2

Please sign in to comment.