[base] Remove base::EraseIf() overloads for std::deque/std::forward_list
They're now replaced with C++20 std::erase_if(). Bug: 1414639 Change-Id: I15c7e0e3cbe1e750901c495600261062d7f6dc42 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5033301 Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Commit-Queue: Andrew Rayskiy <greengrape@google.com> Owners-Override: Kyle Charbonneau <kylechar@chromium.org> Reviewed-by: Kyle Charbonneau <kylechar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1225432}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
6861fb75e4
commit
fb46735ba8
base
cc/metrics
chromecast/device/bluetooth/le
components
content/browser
@ -266,8 +266,6 @@ component("base") {
|
||||
"containers/contains.h",
|
||||
"containers/contiguous_iterator.h",
|
||||
"containers/cxx20_erase.h",
|
||||
"containers/cxx20_erase_deque.h",
|
||||
"containers/cxx20_erase_forward_list.h",
|
||||
"containers/cxx20_erase_internal.h",
|
||||
"containers/cxx20_erase_list.h",
|
||||
"containers/cxx20_erase_map.h",
|
||||
|
@ -5,8 +5,6 @@
|
||||
#ifndef BASE_CONTAINERS_CXX20_ERASE_H_
|
||||
#define BASE_CONTAINERS_CXX20_ERASE_H_
|
||||
|
||||
#include "base/containers/cxx20_erase_deque.h"
|
||||
#include "base/containers/cxx20_erase_forward_list.h"
|
||||
#include "base/containers/cxx20_erase_list.h"
|
||||
#include "base/containers/cxx20_erase_map.h"
|
||||
#include "base/containers/cxx20_erase_set.h"
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Copyright 2021 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef BASE_CONTAINERS_CXX20_ERASE_DEQUE_H_
|
||||
#define BASE_CONTAINERS_CXX20_ERASE_DEQUE_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <iterator>
|
||||
|
||||
namespace base {
|
||||
|
||||
// Erase/EraseIf are based on C++20's uniform container erasure API:
|
||||
// - https://eel.is/c++draft/libraryindex#:erase
|
||||
// - https://eel.is/c++draft/libraryindex#:erase_if
|
||||
// They provide a generic way to erase elements from a container.
|
||||
// The functions here implement these for the standard containers until those
|
||||
// functions are available in the C++ standard.
|
||||
// Note: there is no std::erase for standard associative containers so we don't
|
||||
// have it either.
|
||||
|
||||
template <class T, class Allocator, class Value>
|
||||
size_t Erase(std::deque<T, Allocator>& container, const Value& value) {
|
||||
auto it = std::remove(container.begin(), container.end(), value);
|
||||
size_t removed = std::distance(it, container.end());
|
||||
container.erase(it, container.end());
|
||||
return removed;
|
||||
}
|
||||
|
||||
template <class T, class Allocator, class Predicate>
|
||||
size_t EraseIf(std::deque<T, Allocator>& container, Predicate pred) {
|
||||
auto it = std::remove_if(container.begin(), container.end(), pred);
|
||||
size_t removed = std::distance(it, container.end());
|
||||
container.erase(it, container.end());
|
||||
return removed;
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_CONTAINERS_CXX20_ERASE_DEQUE_H_
|
@ -1,42 +0,0 @@
|
||||
// Copyright 2021 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef BASE_CONTAINERS_CXX20_ERASE_FORWARD_LIST_H_
|
||||
#define BASE_CONTAINERS_CXX20_ERASE_FORWARD_LIST_H_
|
||||
|
||||
#include <forward_list>
|
||||
#include <iterator>
|
||||
|
||||
namespace base {
|
||||
|
||||
// Erase/EraseIf are based on C++20's uniform container erasure API:
|
||||
// - https://eel.is/c++draft/libraryindex#:erase
|
||||
// - https://eel.is/c++draft/libraryindex#:erase_if
|
||||
// They provide a generic way to erase elements from a container.
|
||||
// The functions here implement these for the standard containers until those
|
||||
// functions are available in the C++ standard.
|
||||
// Note: there is no std::erase for standard associative containers so we don't
|
||||
// have it either.
|
||||
|
||||
template <class T, class Allocator, class Predicate>
|
||||
size_t EraseIf(std::forward_list<T, Allocator>& container, Predicate pred) {
|
||||
// Note: std::forward_list does not have a size() API, thus we need to use the
|
||||
// O(n) std::distance work-around. However, given that EraseIf is O(n)
|
||||
// already, this should not make a big difference.
|
||||
size_t old_size = std::distance(container.begin(), container.end());
|
||||
container.remove_if(pred);
|
||||
return old_size - std::distance(container.begin(), container.end());
|
||||
}
|
||||
|
||||
template <class T, class Allocator, class Value>
|
||||
size_t Erase(std::forward_list<T, Allocator>& container, const Value& value) {
|
||||
// Unlike std::forward_list::remove, this function template accepts
|
||||
// heterogeneous types and does not force a conversion to the container's
|
||||
// value type before invoking the == operator.
|
||||
return EraseIf(container, [&](const T& cur) { return cur == value; });
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_CONTAINERS_CXX20_ERASE_FORWARD_LIST_H_
|
@ -13,11 +13,6 @@ size_t GetSize(const Container& c) {
|
||||
return c.size();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t GetSize(const std::forward_list<T>& l) {
|
||||
return std::distance(l.begin(), l.end());
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void RunEraseTest() {
|
||||
const std::pair<Container, Container> test_data[] = {
|
||||
@ -116,21 +111,11 @@ TEST(Erase, String16) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Erase, Deque) {
|
||||
RunEraseTest<std::deque<int>>();
|
||||
RunEraseIfTest<std::deque<std::pair<int, int>>>();
|
||||
}
|
||||
|
||||
TEST(Erase, Vector) {
|
||||
RunEraseTest<std::vector<int>>();
|
||||
RunEraseIfTest<std::vector<std::pair<int, int>>>();
|
||||
}
|
||||
|
||||
TEST(Erase, ForwardList) {
|
||||
RunEraseTest<std::forward_list<int>>();
|
||||
RunEraseIfTest<std::forward_list<std::pair<int, int>>>();
|
||||
}
|
||||
|
||||
TEST(Erase, List) {
|
||||
RunEraseTest<std::list<int>>();
|
||||
RunEraseIfTest<std::list<std::pair<int, int>>>();
|
||||
|
@ -6,12 +6,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
#include "base/metrics/histogram_macros.h"
|
||||
#include "base/notreached.h"
|
||||
#include "base/ranges/algorithm.h"
|
||||
@ -1873,10 +1873,10 @@ void CompositorFrameReporter::DiscardOldPartialUpdateReporters() {
|
||||
return;
|
||||
}
|
||||
// Remove all destroyed reporters from `partial_update_dependents_`.
|
||||
base::EraseIf(partial_update_dependents_,
|
||||
std::erase_if(partial_update_dependents_,
|
||||
[](const base::WeakPtr<CompositorFrameReporter>& reporter) {
|
||||
return !reporter;
|
||||
});
|
||||
return !reporter;
|
||||
});
|
||||
}
|
||||
|
||||
base::WeakPtr<CompositorFrameReporter> CompositorFrameReporter::GetWeakPtr() {
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
#include "chromecast/device/bluetooth/le/gatt_client_manager_impl.h"
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
@ -280,13 +280,13 @@ void GattClientManagerImpl::OnConnectChanged(
|
||||
disconnect_timeout_timer_.Stop();
|
||||
RunQueuedConnectRequest();
|
||||
} else {
|
||||
base::EraseIf(pending_connect_requests_,
|
||||
std::erase_if(pending_connect_requests_,
|
||||
[addr](const PendingRequest& request) {
|
||||
return request.addr == addr;
|
||||
});
|
||||
}
|
||||
|
||||
base::Erase(pending_read_remote_rssi_requests_, addr);
|
||||
std::erase(pending_read_remote_rssi_requests_, addr);
|
||||
read_remote_rssi_timeout_timer_.Stop();
|
||||
|
||||
if (connected_devices_.empty()) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "chromecast/device/bluetooth/le/le_scan_manager_impl.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
@ -202,7 +203,7 @@ void LeScanManagerImpl::OnScanResult(
|
||||
|
||||
// Remove scan_result.addr to avoid duplicate addresses in
|
||||
// recent_scan_result_addr_list_.
|
||||
base::Erase(scan_result_addr_list_, scan_result.addr);
|
||||
std::erase(scan_result_addr_list_, scan_result.addr);
|
||||
}
|
||||
|
||||
previous_scan_results.push_front(scan_result);
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
#include "components/policy/core/common/policy_logger.h"
|
||||
|
||||
#include <deque>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/i18n/time_formatting.h"
|
||||
#include "base/no_destructor.h"
|
||||
@ -195,7 +195,7 @@ void PolicyLogger::DeleteOldLogs() {
|
||||
// Delete older logs with lifetime `kTimeToLive` mins, set the flag and
|
||||
// reschedule the task.
|
||||
base::AutoLock lock(lock_);
|
||||
base::EraseIf(logs_, IsLogExpired);
|
||||
std::erase_if(logs_, IsLogExpired);
|
||||
|
||||
if (logs_.size() > 0) {
|
||||
ScheduleOldLogsDeletion();
|
||||
|
@ -4,10 +4,11 @@
|
||||
|
||||
#include "components/zucchini/equivalence_map.h"
|
||||
|
||||
#include <deque>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/safe_conversions.h"
|
||||
#include "base/ranges/algorithm.h"
|
||||
@ -305,7 +306,7 @@ void OffsetMapper::ForwardProjectAll(std::deque<offset_t>* offsets) const {
|
||||
src = kInvalidOffset;
|
||||
}
|
||||
}
|
||||
base::Erase(*offsets, kInvalidOffset);
|
||||
std::erase(*offsets, kInvalidOffset);
|
||||
offsets->shrink_to_fit();
|
||||
}
|
||||
|
||||
@ -382,7 +383,7 @@ void OffsetMapper::PruneEquivalencesAndSortBySource(
|
||||
}
|
||||
|
||||
// Discard all equivalences with length == 0.
|
||||
base::EraseIf(*equivalences, [](const Equivalence& equivalence) {
|
||||
std::erase_if(*equivalences, [](const Equivalence& equivalence) {
|
||||
return equivalence.length == 0;
|
||||
});
|
||||
equivalences->shrink_to_fit();
|
||||
@ -558,7 +559,7 @@ void EquivalenceMap::Prune(
|
||||
}
|
||||
|
||||
// Discard all candidates with similarity smaller than |min_similarity|.
|
||||
base::EraseIf(candidates_,
|
||||
std::erase_if(candidates_,
|
||||
[min_similarity](const EquivalenceCandidate& candidate) {
|
||||
return candidate.similarity < min_similarity;
|
||||
});
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/cxx20_erase_forward_list.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "content/browser/devtools/devtools_agent_host_impl.h"
|
||||
@ -40,7 +39,7 @@ MojomDevToolsAgentHost::MojomDevToolsAgentHost(
|
||||
MojomDevToolsAgentHost::~MojomDevToolsAgentHost() {
|
||||
associated_agent_remote_.reset();
|
||||
delegate_.reset();
|
||||
base::Erase(host_ids(), GetId());
|
||||
std::erase(host_ids(), GetId());
|
||||
}
|
||||
|
||||
// Devtools Agent host overrides:
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
#include "base/debug/crash_logging.h"
|
||||
#include "base/debug/dump_without_crashing.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
@ -208,7 +207,7 @@ void TouchEventAckQueue::ProcessAckedTouchEvents() {
|
||||
void TouchEventAckQueue::UpdateQueueAfterTargetDestroyed(
|
||||
RenderWidgetHostViewBase* target_view) {
|
||||
// If a queue entry's root view is being destroyed, just delete it.
|
||||
base::EraseIf(ack_queue_, [target_view](AckData data) {
|
||||
std::erase_if(ack_queue_, [target_view](AckData data) {
|
||||
return data.root_view == target_view;
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user