llvm.org GIT mirror llvm / 303ca2d
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 Nico Weber a month ago
1 changed file(s) with 8 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
3636 class HashTableIterator
3737 : public iterator_facade_base,
3838 std::forward_iterator_tag,
39 std::pair> {
39 const std::pair> {
4040 friend HashTable;
4141
4242 HashTableIterator(const HashTable &Map, uint32_t Index,
9393
9494 template
9595 class HashTable {
96 using iterator = HashTableIterator;
97 friend iterator;
96 using const_iterator = HashTableIterator;
97 friend const_iterator;
9898
9999 struct Header {
100100 support::ulittle32_t Size;
205205 uint32_t capacity() const { return Buckets.size(); }
206206 uint32_t size() const { return Present.count(); }
207207
208 iterator begin() const { return iterator(*this); }
209 iterator end() const { return iterator(*this, 0, true); }
208 const_iterator begin() const { return const_iterator(*this); }
209 const_iterator end() const { return const_iterator(*this, 0, true); }
210210
211211 /// Find the entry whose key has the specified hash value, using the specified
212212 /// traits defining hash function and equality.
213213 template
214 iterator find_as(const Key &K, TraitsT &Traits) const {
214 const_iterator find_as(const Key &K, TraitsT &Traits) const {
215215 uint32_t H = Traits.hashLookupKey(K) % capacity();
216216 uint32_t I = H;
217217 Optional FirstUnused;
218218 do {
219219 if (isPresent(I)) {
220220 if (Traits.storageKeyToLookupKey(Buckets[I].first) == K)
221 return iterator(*this, I, false);
221 return const_iterator(*this, I, false);
222222 } else {
223223 if (!FirstUnused)
224224 FirstUnused = I;
237237 // table were Present. But this would violate the load factor constraints
238238 // that we impose, so it should never happen.
239239 assert(FirstUnused);
240 return iterator(*this, *FirstUnused, true);
240 return const_iterator(*this, *FirstUnused, true);
241241 }
242242
243243 /// Set the entry using a key type that the specified Traits can convert