Changes in directory llvm/lib/Support:
StringMap.cpp updated: 1.10 -> 1.11 --- Log message: Extend StringMap to support being initialized as completely empty. When initialized this way, they do not do a malloc to allocate their buckets. --- Diffs of the changes: (+22 -2) StringMap.cpp | 24 ++++++++++++++++++++++-- 1 files changed, 22 insertions(+), 2 deletions(-) Index: llvm/lib/Support/StringMap.cpp diff -u llvm/lib/Support/StringMap.cpp:1.10 llvm/lib/Support/StringMap.cpp:1.11 --- llvm/lib/Support/StringMap.cpp:1.10 Tue Apr 3 17:15:38 2007 +++ llvm/lib/Support/StringMap.cpp Tue Apr 3 19:29:37 2007 @@ -16,10 +16,25 @@ using namespace llvm; StringMapImpl::StringMapImpl(unsigned InitSize, unsigned itemSize) { + ItemSize = itemSize; + + // If a size is specified, initialize the table with that many buckets. + if (InitSize) { + init(InitSize); + return; + } + + // Otherwise, initialize it with zero buckets to avoid the allocation. + TheTable = 0; + NumBuckets = 0; + NumItems = 0; + NumTombstones = 0; +} + +void StringMapImpl::init(unsigned InitSize) { assert((InitSize & (InitSize-1)) == 0 && "Init Size must be a power of 2 or zero!"); NumBuckets = InitSize ? InitSize : 16; - ItemSize = itemSize; NumItems = 0; NumTombstones = 0; @@ -52,8 +67,12 @@ /// case, the FullHashValue field of the bucket will be set to the hash value /// of the string. unsigned StringMapImpl::LookupBucketFor(const char *NameStart, - const char *NameEnd) { + const char *NameEnd) { unsigned HTSize = NumBuckets; + if (HTSize == 0) { // Hash table unallocated so far? + init(16); + HTSize = NumBuckets; + } unsigned FullHashValue = HashString(NameStart, NameEnd); unsigned BucketNo = FullHashValue & (HTSize-1); @@ -110,6 +129,7 @@ /// This does not modify the map. int StringMapImpl::FindKey(const char *KeyStart, const char *KeyEnd) const { unsigned HTSize = NumBuckets; + if (HTSize == 0) return -1; // Really empty table? unsigned FullHashValue = HashString(KeyStart, KeyEnd); unsigned BucketNo = FullHashValue & (HTSize-1); _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits