[CodeHealth] Apply performance-move-const-arg (#26497)

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 https://github.com/brave/brave-browser/issues/42230
This commit is contained in:
cdesouza-chromium
2024-11-12 12:08:03 -05:00
committed by GitHub
parent d0becfcd17
commit 4ffbda2340
9 changed files with 13 additions and 14 deletions
@@ -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,
@@ -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));
}
}
@@ -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));
}
@@ -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;
@@ -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));
}
+4 -4
View File
@@ -133,7 +133,7 @@ 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);
@@ -141,15 +141,15 @@ P3AConfig P3AConfig::LoadFromCommandLine() {
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);
@@ -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;
@@ -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));
+1 -1
View File
@@ -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)),
+1 -1
View File
@@ -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();