From 303ca2d4a8680e0fe4ed84718920f6eaddf6224d Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 15 Jul 2019 12:10:02 +0000 Subject: [PATCH] PDB HashTable: Make iterator key type const Having the hash table key change during iteration is bad, so make it impossible. Nothing relied on the key type not being const. (This is also necessary to be able to call the const version of iterator_facade_base::operator->(). Nothing calls this, and nothing will, but I tried using it locally during development and it took me a while to understand what was going wrong.) Also rename the iterator typedef to const_iterator. No behavior change. Differential Revision: https://reviews.llvm.org/D64641 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366060 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/PDB/Native/HashTable.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/llvm/DebugInfo/PDB/Native/HashTable.h b/include/llvm/DebugInfo/PDB/Native/HashTable.h index b00873b575b..e045cc28f71 100644 --- a/include/llvm/DebugInfo/PDB/Native/HashTable.h +++ b/include/llvm/DebugInfo/PDB/Native/HashTable.h @@ -37,7 +37,7 @@ template class HashTableIterator : public iterator_facade_base, std::forward_iterator_tag, - std::pair> { + const std::pair> { friend HashTable; HashTableIterator(const HashTable &Map, uint32_t Index, @@ -94,8 +94,8 @@ private: template class HashTable { - using iterator = HashTableIterator; - friend iterator; + using const_iterator = HashTableIterator; + friend const_iterator; struct Header { support::ulittle32_t Size; @@ -206,20 +206,20 @@ public: uint32_t capacity() const { return Buckets.size(); } uint32_t size() const { return Present.count(); } - iterator begin() const { return iterator(*this); } - iterator end() const { return iterator(*this, 0, true); } + const_iterator begin() const { return const_iterator(*this); } + const_iterator end() const { return const_iterator(*this, 0, true); } /// Find the entry whose key has the specified hash value, using the specified /// traits defining hash function and equality. template - iterator find_as(const Key &K, TraitsT &Traits) const { + const_iterator find_as(const Key &K, TraitsT &Traits) const { uint32_t H = Traits.hashLookupKey(K) % capacity(); uint32_t I = H; Optional FirstUnused; do { if (isPresent(I)) { if (Traits.storageKeyToLookupKey(Buckets[I].first) == K) - return iterator(*this, I, false); + return const_iterator(*this, I, false); } else { if (!FirstUnused) FirstUnused = I; @@ -238,7 +238,7 @@ public: // table were Present. But this would violate the load factor constraints // that we impose, so it should never happen. assert(FirstUnused); - return iterator(*this, *FirstUnused, true); + return const_iterator(*this, *FirstUnused, true); } /// Set the entry using a key type that the specified Traits can convert -- 2.40.0