[llvm-commits] CVS: llvm/include/llvm/ADT/StringMap.h
Chris Lattner
sabre at nondot.org
Sun Feb 11 13:46:52 PST 2007
Changes in directory llvm/include/llvm/ADT:
StringMap.h updated: 1.11 -> 1.12
---
Log message:
add new ShouldRehash method to factor out common code. Fix the dtor to not
delete tombstones.
---
Diffs of the changes: (+14 -12)
StringMap.h | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
Index: llvm/include/llvm/ADT/StringMap.h
diff -u llvm/include/llvm/ADT/StringMap.h:1.11 llvm/include/llvm/ADT/StringMap.h:1.12
--- llvm/include/llvm/ADT/StringMap.h:1.11 Sun Feb 11 15:07:36 2007
+++ llvm/include/llvm/ADT/StringMap.h Sun Feb 11 15:46:36 2007
@@ -58,6 +58,16 @@
StringMapImpl(unsigned InitSize, unsigned ItemSize);
void RehashTable();
+ /// ShouldRehash - Return true if the table should be rehashed after a new
+ /// element was recently inserted.
+ bool ShouldRehash() const {
+ // If the hash table is now more than 3/4 full, or if fewer than 1/8 of
+ // the buckets are empty (meaning that many are filled with tombstones),
+ // grow the table.
+ return NumItems*4 > NumBuckets*3 ||
+ NumBuckets-(NumItems+NumTombstones) < NumBuckets/8;
+ }
+
/// LookupBucketFor - Look up the bucket that the specified string should end
/// up in. If it already exists as a key in the map, the Item pointer for the
/// specified bucket will be non-null. Otherwise, it will be null. In either
@@ -218,11 +228,7 @@
Bucket.Item = KeyValue;
++NumItems;
- // If the hash table is now more than 3/4 full, or if fewer than 1/8 of
- // the buckets are empty (meaning that many are filled with tombstones),
- // grow the table.
- if (NumItems*4 > NumBuckets*3 ||
- NumBuckets-(NumItems+NumTombstones) < NumBuckets/8)
+ if (ShouldRehash())
RehashTable();
return true;
}
@@ -247,11 +253,7 @@
// filled in by LookupBucketFor.
Bucket.Item = NewItem;
- // If the hash table is now more than 3/4 full, or if fewer than 1/8 of
- // the buckets are empty (meaning that many are filled with tombstones),
- // grow the table.
- if (NumItems*4 > NumBuckets*3 ||
- NumBuckets-(NumItems+NumTombstones) < NumBuckets/8)
+ if (ShouldRehash())
RehashTable();
return *NewItem;
}
@@ -264,8 +266,8 @@
~StringMap() {
for (ItemBucket *I = TheTable, *E = TheTable+NumBuckets; I != E; ++I) {
- if (MapEntryTy *Id = static_cast<MapEntryTy*>(I->Item))
- Id->Destroy(Allocator);
+ if (I->Item && I->Item != getTombstoneVal())
+ static_cast<MapEntryTy*>(I->Item)->Destroy(Allocator);
}
delete [] TheTable;
}
More information about the llvm-commits
mailing list