llvm.org GIT mirror llvm / 6ad5fde
Have DenseMap auto-shrink itself on clear(). This improves the time to optimize 403.gcc from 15.2s to 14.3s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40100 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
1 changed file(s) with 36 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
8989 unsigned size() const { return NumEntries; }
9090
9191 void clear() {
92 if (NumEntries * 4 < NumBuckets && NumBuckets > 64) {
93 shrink_and_clear();
94 return;
95 }
96
9297 const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
9398 for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
9499 if (P->first != EmptyKey && P->first != TombstoneKey) {
100105 assert(NumEntries == 0 && "Node count imbalance!");
101106 NumTombstones = 0;
102107 }
103
108
104109 /// count - Return true if the specified key is in the map.
105110 bool count(const KeyT &Val) const {
106111 BucketT *TheBucket;
289294 // Free the old table.
290295 delete[] (char*)OldBuckets;
291296 }
297
298 void shrink_and_clear() {
299 unsigned OldNumBuckets = NumBuckets;
300 BucketT *OldBuckets = Buckets;
301
302 // Halve the number of buckets.
303 NumBuckets >>= 1;
304 NumTombstones = 0;
305 Buckets = (BucketT*)new char[sizeof(BucketT)*NumBuckets];
306
307 // Initialize all the keys to EmptyKey.
308 const KeyT EmptyKey = getEmptyKey();
309 for (unsigned i = 0, e = NumBuckets; i != e; ++i)
310 new (&Buckets[i].first) KeyT(EmptyKey);
311
312 // Free the old buckets.
313 const KeyT TombstoneKey = getTombstoneKey();
314 for (BucketT *B = OldBuckets, *E = OldBuckets+OldNumBuckets; B != E; ++B) {
315 if (B->first != EmptyKey && B->first != TombstoneKey) {
316 // Free the value.
317 B->second.~ValueT();
318 }
319 B->first.~KeyT();
320 }
321
322 // Free the old table.
323 delete[] (char*)OldBuckets;
324
325 NumEntries = 0;
326 }
292327 };
293328
294329 template