aboutsummaryrefslogtreecommitdiff
path: root/absl/container
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2024-02-08 16:30:05 -0800
committerCopybara-Service <copybara-worker@google.com>2024-02-08 16:30:55 -0800
commit760b21530ffc22ef4859356e543022b18de7d2ce (patch)
treecc9e18f46ce9bd866c68ebb513345866c25176f3 /absl/container
parent8eadbbac42ead8b516ed0b802d2668650d9218ec (diff)
downloadabseil-760b21530ffc22ef4859356e543022b18de7d2ce.tar.gz
abseil-760b21530ffc22ef4859356e543022b18de7d2ce.tar.bz2
abseil-760b21530ffc22ef4859356e543022b18de7d2ce.zip
Make `begin()` to return `end()` on empty tables.
PiperOrigin-RevId: 605460827 Change-Id: I57007a7ad18829e7bfed27ba65871afbd227d012
Diffstat (limited to 'absl/container')
-rw-r--r--absl/container/internal/raw_hash_set.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index dced5b2b..d6950e61 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -2027,6 +2027,7 @@ class raw_hash_set {
++ctrl_;
++slot_;
skip_empty_or_deleted();
+ if (ABSL_PREDICT_FALSE(*ctrl_ == ctrl_t::kSentinel)) ctrl_ = nullptr;
return *this;
}
// PRECONDITION: not an end() iterator.
@@ -2061,10 +2062,8 @@ class raw_hash_set {
explicit iterator(const GenerationType* generation_ptr)
: HashSetIteratorGenerationInfo(generation_ptr), ctrl_(nullptr) {}
- // Fixes up `ctrl_` to point to a full by advancing it and `slot_` until
- // they reach one.
- //
- // If a sentinel is reached, we null `ctrl_` out instead.
+ // Fixes up `ctrl_` to point to a full or sentinel by advancing `ctrl_` and
+ // `slot_` until they reach one.
void skip_empty_or_deleted() {
while (IsEmptyOrDeleted(*ctrl_)) {
uint32_t shift =
@@ -2072,7 +2071,6 @@ class raw_hash_set {
ctrl_ += shift;
slot_ += shift;
}
- if (ABSL_PREDICT_FALSE(*ctrl_ == ctrl_t::kSentinel)) ctrl_ = nullptr;
}
ctrl_t* control() const { return ctrl_; }
@@ -2369,8 +2367,11 @@ class raw_hash_set {
~raw_hash_set() { destructor_impl(); }
iterator begin() ABSL_ATTRIBUTE_LIFETIME_BOUND {
+ // TODO(b/324478958): Consider reverting if no impact.
+ if (ABSL_PREDICT_FALSE(empty())) return end();
auto it = iterator_at(0);
it.skip_empty_or_deleted();
+ assert(IsFull(*it.control()));
return it;
}
iterator end() ABSL_ATTRIBUTE_LIFETIME_BOUND {