Skip to content

Commit

Permalink
[base] Remove base::Erase()/base::EraseIf() overloads for std::list
Browse files Browse the repository at this point in the history
They're now replaced with C++20 std::erase()/std::erase_if().

Bug: 1414639
Change-Id: I2f38a845f132bb4115563547f3669f79b7b6c7ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5049925
Commit-Queue: Andrew Rayskiy <[email protected]>
Reviewed-by: Kyle Charbonneau <[email protected]>
Owners-Override: Kyle Charbonneau <[email protected]>
Code-Coverage: [email protected] <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1228003}
  • Loading branch information
GrapeGreen authored and Chromium LUCI CQ committed Nov 22, 2023
1 parent 5e49c8b commit be08b98
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 81 deletions.
1 change: 0 additions & 1 deletion base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ component("base") {
"containers/contains.h",
"containers/cxx20_erase.h",
"containers/cxx20_erase_internal.h",
"containers/cxx20_erase_list.h",
"containers/cxx20_erase_map.h",
"containers/cxx20_erase_set.h",
"containers/cxx20_erase_string.h",
Expand Down
3 changes: 1 addition & 2 deletions base/callback_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/auto_reset.h"
#include "base/base_export.h"
#include "base/check.h"
#include "base/containers/cxx20_erase_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
Expand Down Expand Up @@ -228,7 +227,7 @@ class CallbackListBase {
// Any null callbacks remaining in the list were canceled due to
// Subscription destruction during iteration, and can safely be erased now.
const size_t erased_callbacks =
EraseIf(callbacks_, [](const auto& cb) { return cb.is_null(); });
std::erase_if(callbacks_, [](const auto& cb) { return cb.is_null(); });

// Run |removal_callback_| if any callbacks were canceled. Note that we
// cannot simply compare list sizes before and after iterating, since
Expand Down
1 change: 0 additions & 1 deletion base/containers/cxx20_erase.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef BASE_CONTAINERS_CXX20_ERASE_H_
#define BASE_CONTAINERS_CXX20_ERASE_H_

#include "base/containers/cxx20_erase_list.h"
#include "base/containers/cxx20_erase_map.h"
#include "base/containers/cxx20_erase_set.h"
#include "base/containers/cxx20_erase_string.h"
Expand Down
38 changes: 0 additions & 38 deletions base/containers/cxx20_erase_list.h

This file was deleted.

5 changes: 0 additions & 5 deletions base/containers/erase_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ TEST(Erase, Vector) {
RunEraseIfTest<std::vector<std::pair<int, int>>>();
}

TEST(Erase, List) {
RunEraseTest<std::list<int>>();
RunEraseIfTest<std::list<std::pair<int, int>>>();
}

TEST(Erase, Map) {
RunEraseIfTest<std::map<int, int>>();
RunEraseIfTest<std::map<int, int, std::greater<>>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#include "chrome/browser/ash/app_restore/arc_app_queue_restore_handler.h"

#include <list>
#include <utility>
#include <vector>

#include "ash/components/arc/arc_util.h"
#include "ash/components/arc/metrics/arc_metrics_constants.h"
#include "ash/shell.h"
#include "base/containers/contains.h"
#include "base/containers/cxx20_erase.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_functions.h"
Expand Down Expand Up @@ -574,7 +574,7 @@ void ArcAppQueueRestoreHandler::MaybeLaunchApp() {
const WindowInfo info = *it;
LaunchAppWindow(info.app_id, info.window_id);
MaybeReStartTimer(kAppLaunchDelay);
base::Erase(pending_windows_, info);
std::erase(pending_windows_, info);
return;
}

Expand Down Expand Up @@ -603,7 +603,7 @@ void ArcAppQueueRestoreHandler::MaybeLaunchApp() {
const WindowInfo info = *it;
LaunchAppWindow(info.app_id, info.window_id);
MaybeReStartTimer(kAppLaunchDelay);
base::Erase(no_stack_windows_, info);
std::erase(no_stack_windows_, info);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#include "chrome/browser/new_tab_page/modules/recipes/recipes_service.h"

#include <list>

#include "base/containers/contains.h"
#include "base/containers/cxx20_erase.h"
#include "base/hash/hash.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
Expand Down Expand Up @@ -170,7 +171,7 @@ void RecipesService::OnDataLoaded(network::SimpleURLLoader* loader,
std::unique_ptr<std::string> response) {
auto net_error = loader->NetError();
bool loaded_from_cache = loader->LoadedFromCache();
base::EraseIf(loaders_, [loader](const auto& target) {
std::erase_if(loaders_, [loader](const auto& target) {
return loader == target.get();
});

Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/ash/app_access_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chrome/browser/ui/ash/app_access_notifier.h"

#include <list>
#include <string>
#include <vector>

Expand All @@ -14,7 +15,6 @@
#include "ash/system/privacy_hub/camera_privacy_switch_controller.h"
#include "ash/system/privacy_hub/privacy_hub_controller.h"
#include "base/check.h"
#include "base/containers/cxx20_erase.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/metrics/histogram_functions.h"
Expand Down Expand Up @@ -171,7 +171,7 @@ void AppAccessNotifier::OnCapabilityAccessUpdate(
SendActiveCameraApplicationsChangedNotification(/*application_added=*/true);
} else if (!is_camera_used && was_using_camera_already) {
// App with id `app_id` stopped using camera.
base::Erase(camera_using_app_ids_[active_user_account_id_], update.AppId());
std::erase(camera_using_app_ids_[active_user_account_id_], update.AppId());
SendActiveCameraApplicationsChangedNotification(
/*application_added=*/false);
}
Expand All @@ -181,7 +181,7 @@ void AppAccessNotifier::OnCapabilityAccessUpdate(
mic_using_app_ids_[active_user_account_id_].push_front(update.AppId());
} else if (!is_microphone_used && was_using_microphone_already) {
// App with id `app_id` stopped using microphone.
base::Erase(mic_using_app_ids_[active_user_account_id_], update.AppId());
std::erase(mic_using_app_ids_[active_user_account_id_], update.AppId());
}

if (ash::features::IsPrivacyIndicatorsEnabled()) {
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/ui/webui/ash/system_web_dialog_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "ash/public/cpp/shell_window_ids.h"
#include "base/containers/contains.h"
#include "base/containers/cxx20_erase.h"
#include "base/no_destructor.h"
#include "base/ranges/algorithm.h"
#include "chrome/browser/profiles/profile_manager.h"
Expand Down Expand Up @@ -157,7 +156,7 @@ SystemWebDialogDelegate::SystemWebDialogDelegate(const GURL& url,
}

SystemWebDialogDelegate::~SystemWebDialogDelegate() {
base::EraseIf(*GetInstances(),
std::erase_if(*GetInstances(),
[this](SystemWebDialogDelegate* i) { return i == this; });
}

Expand Down
1 change: 0 additions & 1 deletion components/exo/wayland/zaura_shell_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "ash/shell.h"
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/window_util.h"
#include "base/containers/cxx20_erase_list.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "components/exo/buffer.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#include "components/signin/internal/identity_manager/fake_profile_oauth2_token_service_delegate.h"

#include <list>
#include <memory>
#include <vector>

#include "base/containers/cxx20_erase.h"
#include "base/ranges/algorithm.h"
#include "build/build_config.h"
#include "components/signin/internal/identity_manager/profile_oauth2_token_service.h"
Expand Down Expand Up @@ -92,7 +92,7 @@ void FakeProfileOAuth2TokenServiceDelegate::IssueRefreshTokenForUser(
const CoreAccountId& account_id,
const std::string& token) {
if (token.empty()) {
base::Erase(account_ids_, account_id);
std::erase(account_ids_, account_id);
refresh_tokens_.erase(account_id);
ClearAuthError(account_id);
FireRefreshTokenRevoked(account_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <string>
#include <vector>

#include "base/containers/cxx20_erase_list.h"
#include "base/files/file_util.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/web_contents/web_contents_impl.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "content/browser/file_system_access/file_system_access_watcher_manager.h"

#include <algorithm>
#include <list>
#include <memory>

#include "base/check.h"
#include "base/containers/cxx20_erase_list.h"
#include "base/functional/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
Expand Down Expand Up @@ -205,7 +205,7 @@ void FileSystemAccessWatcherManager::OnSourceBeingDestroyed(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

source_observations_.RemoveObservation(source);
size_t count_removed = base::Erase(all_sources_, *source);
size_t count_removed = std::erase(all_sources_, *source);
CHECK_EQ(count_removed, 1u);
}

Expand Down
4 changes: 2 additions & 2 deletions content/browser/media/media_internals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#include <stddef.h>

#include <list>
#include <string>
#include <tuple>
#include <utility>

#include "base/containers/adapters.h"
#include "base/containers/cxx20_erase.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
Expand Down Expand Up @@ -672,7 +672,7 @@ void MediaInternals::SaveEvent(int process_id,
// Remove all events for a given player as soon as we have to remove a
// single event for that player to avoid showing incomplete players.
const int id_to_remove = saved_events.front().id;
base::EraseIf(saved_events, [&](const media::MediaLogRecord& event) {
std::erase_if(saved_events, [&](const media::MediaLogRecord& event) {
return event.id == id_to_remove;
});
}
Expand Down
4 changes: 2 additions & 2 deletions content/browser/renderer_host/back_forward_cache_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#include "content/browser/renderer_host/back_forward_cache_impl.h"

#include <list>
#include <string>
#include <vector>

#include "base/barrier_closure.h"
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/cxx20_erase.h"
#include "base/containers/enum_set.h"
#include "base/functional/bind.h"
#include "base/memory/weak_ptr.h"
Expand Down Expand Up @@ -1497,7 +1497,7 @@ void BackForwardCacheImpl::DestroyEvictedFrames() {
if (entries_.empty())
return;

base::EraseIf(entries_, [this](std::unique_ptr<Entry>& entry) {
std::erase_if(entries_, [this](std::unique_ptr<Entry>& entry) {
if (entry->render_frame_host()->is_evicted_from_back_forward_cache()) {
RemoveProcessesForEntry(*entry);
return true;
Expand Down
12 changes: 7 additions & 5 deletions extensions/browser/api/declarative_net_request/action_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "extensions/browser/api/declarative_net_request/action_tracker.h"

#include <list>
#include <map>
#include <tuple>
#include <utility>

Expand Down Expand Up @@ -206,8 +208,8 @@ void ActionTracker::ClearExtensionData(const ExtensionId& extension_id) {
return it.first.extension_id == extension_id;
};

base::EraseIf(rules_tracked_, compare_by_extension_id);
base::EraseIf(pending_navigation_actions_, compare_by_extension_id);
std::erase_if(rules_tracked_, compare_by_extension_id);
std::erase_if(pending_navigation_actions_, compare_by_extension_id);

// Stop the timer if there are no more matched rules or pending actions.
if (rules_tracked_.empty() && pending_navigation_actions_.empty())
Expand All @@ -225,7 +227,7 @@ void ActionTracker::ClearTabData(int tab_id) {
return matches_tab_id;
};

base::EraseIf(rules_tracked_, compare_by_tab_id);
std::erase_if(rules_tracked_, compare_by_tab_id);
}

void ActionTracker::ClearPendingNavigation(int64_t navigation_id) {
Expand All @@ -235,7 +237,7 @@ void ActionTracker::ClearPendingNavigation(int64_t navigation_id) {
return it.first.secondary_id == navigation_id;
};

base::EraseIf(pending_navigation_actions_, compare_by_navigation_id);
std::erase_if(pending_navigation_actions_, compare_by_navigation_id);
}

void ActionTracker::ResetTrackedInfoForTab(int tab_id, int64_t navigation_id) {
Expand Down Expand Up @@ -475,7 +477,7 @@ void ActionTracker::TrimRulesFromNonActiveTabs() {
}

TrackedInfo& tracked_info = it->second;
base::EraseIf(tracked_info.matched_rules, older_than_lifespan);
std::erase_if(tracked_info.matched_rules, older_than_lifespan);

if (tracked_info.matched_rules.empty())
it = rules_tracked_.erase(it);
Expand Down
11 changes: 7 additions & 4 deletions net/http/http_auth_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "net/http/http_auth_cache.h"

#include <list>
#include <map>

#include "base/containers/cxx20_erase.h"
#include "base/logging.h"
#include "base/memory/raw_ptr_exclusion.h"
Expand Down Expand Up @@ -56,7 +59,7 @@ void CheckPathIsValid(const std::string& path) {
}
#endif

// Functor used by EraseIf.
// Functor used by std::erase_if.
struct IsEnclosedBy {
explicit IsEnclosedBy(const std::string& path) : path(path) { }
bool operator() (const std::string& x) const {
Expand Down Expand Up @@ -87,7 +90,7 @@ void HttpAuthCache::SetKeyServerEntriesByNetworkAnonymizationKey(

key_server_entries_by_network_anonymization_key_ =
key_server_entries_by_network_anonymization_key;
base::EraseIf(entries_, [](EntryMap::value_type& entry_map_pair) {
std::erase_if(entries_, [](EntryMap::value_type& entry_map_pair) {
return entry_map_pair.first.target == HttpAuth::AUTH_SERVER;
});
}
Expand Down Expand Up @@ -246,7 +249,7 @@ void HttpAuthCache::Entry::AddPath(const std::string& path) {
std::string parent_dir = GetParentDirectory(path);
if (!HasEnclosingPath(parent_dir, nullptr)) {
// Remove any entries that have been subsumed by the new entry.
base::EraseIf(paths_, IsEnclosedBy(parent_dir));
std::erase_if(paths_, IsEnclosedBy(parent_dir));

// Failsafe to prevent unbounded memory growth of the cache.
//
Expand Down Expand Up @@ -311,7 +314,7 @@ void HttpAuthCache::ClearEntriesAddedBetween(
ClearAllEntries();
return;
}
base::EraseIf(entries_, [begin_time, end_time,
std::erase_if(entries_, [begin_time, end_time,
url_matcher](EntryMap::value_type& entry_map_pair) {
Entry& entry = entry_map_pair.second;
return entry.creation_time_ >= begin_time &&
Expand Down
Loading

0 comments on commit be08b98

Please sign in to comment.