aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2021-08-24 11:18:06 -0700
committerGravatar rogeeff <rogeeff@google.com>2021-08-25 03:32:35 -0400
commit095dfc24ff35e5c90f341eac832bdccb891dc35a (patch)
treef58f14d5f93cd6b31870041b9c41d333ff4f3041
parent9134967d017fcd09f71539c8957b73eb05c26f45 (diff)
Export of internal Abseil changes
-- 5d05c54a619a969da5b4b7f66a2af2d969dc7920 by Abseil Team <absl-team@google.com>: Save not needed copies of the predicate in raw_hash_set's EraseIf. PiperOrigin-RevId: 392706073 -- 61ee9b808cd3c81dd10a600c8de5428d6a43cfeb by Abseil Team <absl-team@google.com>: Save unnecessary copies of the iterator in raw_hash_set's EraseIf. PiperOrigin-RevId: 392668288 GitOrigin-RevId: 5d05c54a619a969da5b4b7f66a2af2d969dc7920 Change-Id: I180dab2706841ce56f27cf6eabdad1106ebdcf73
-rw-r--r--absl/container/internal/raw_hash_set.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index 18b1f5a..f4919ce 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -1921,11 +1921,12 @@ class raw_hash_set {
// Erases all elements that satisfy the predicate `pred` from the container `c`.
template <typename P, typename H, typename E, typename A, typename Predicate>
-void EraseIf(Predicate pred, raw_hash_set<P, H, E, A>* c) {
+void EraseIf(Predicate& pred, raw_hash_set<P, H, E, A>* c) {
for (auto it = c->begin(), last = c->end(); it != last;) {
- auto copy_it = it++;
- if (pred(*copy_it)) {
- c->erase(copy_it);
+ if (pred(*it)) {
+ c->erase(it++);
+ } else {
+ ++it;
}
}
}