summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-11-11 13:12:21 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2022-11-11 13:13:18 -0800
commit1b976982d8cdbfd8320f34209b065bae7adefb09 (patch)
tree1236085664ae3272aa94d2b26f98b6389b20fbf6 /absl
parent3a35cb3dffea155c6778cf43bc023fca583730e0 (diff)
Stop unnecessary clearing of fields in ~raw_hash_set.
Previously, ~raw_hash_set() would change *this to have the same representation as an empty hash table. This is unnecessary since nobody should be touching a destroyed hash table, and prevents future optimizations/changes that might not be able to preserve this behavior. PiperOrigin-RevId: 487899950 Change-Id: I2d4470677bdd411c2e48ef511187e39f4e7fc2f4
Diffstat (limited to 'absl')
-rw-r--r--absl/container/internal/raw_hash_set.h24
1 files changed, 13 insertions, 11 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index 1aa89204..de455d6c 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -1364,7 +1364,7 @@ class raw_hash_set {
typename AllocTraits::propagate_on_container_move_assignment());
}
- ~raw_hash_set() { destroy_slots(); }
+ ~raw_hash_set() { destroy_slots(/*reset=*/false); }
iterator begin() {
auto it = iterator_at(0);
@@ -1394,7 +1394,7 @@ class raw_hash_set {
// largest bucket_count() threshold for which iteration is still fast and
// past that we simply deallocate the array.
if (capacity_ > 127) {
- destroy_slots();
+ destroy_slots(/*reset=*/true);
infoz().RecordClearedReservation();
} else if (capacity_) {
@@ -1707,7 +1707,7 @@ class raw_hash_set {
void rehash(size_t n) {
if (n == 0 && capacity_ == 0) return;
if (n == 0 && size_ == 0) {
- destroy_slots();
+ destroy_slots(/*reset=*/true);
infoz().RecordStorageChanged(0, 0);
infoz().RecordClearedReservation();
return;
@@ -1985,11 +1985,11 @@ class raw_hash_set {
infoz().RecordStorageChanged(size_, capacity_);
}
- // Destroys all slots in the backing array, frees the backing array, and
- // clears all top-level book-keeping data.
+ // Destroys all slots in the backing array, frees the backing array,
+ // If reset is true, also clears all top-level book-keeping data.
//
// This essentially implements `map = raw_hash_set();`.
- void destroy_slots() {
+ void destroy_slots(bool reset) {
if (!capacity_) return;
for (size_t i = 0; i != capacity_; ++i) {
if (IsFull(ctrl_[i])) {
@@ -2002,11 +2002,13 @@ class raw_hash_set {
Deallocate<alignof(slot_type)>(
&alloc_ref(), ctrl_,
AllocSize(capacity_, sizeof(slot_type), alignof(slot_type)));
- ctrl_ = EmptyGroup();
- slots_ = nullptr;
- size_ = 0;
- capacity_ = 0;
- growth_left() = 0;
+ if (reset) {
+ ctrl_ = EmptyGroup();
+ slots_ = nullptr;
+ size_ = 0;
+ capacity_ = 0;
+ growth_left() = 0;
+ }
}
void resize(size_t new_capacity) {