diff options
author | Chris Lattner <sabre@nondot.org> | 2007-02-11 08:20:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-02-11 08:20:35 +0000 |
commit | e15605ccbf838770a495652215bfc3068b4b8508 (patch) | |
tree | 7fc92e4fa65b317afc3319be7612502f5b3c2dee /llvm/lib/Support/StringMap.cpp | |
parent | aac10ff6bfdfa316cd6d16f1e84dc8a676f5d859 (diff) | |
download | bcm5719-llvm-e15605ccbf838770a495652215bfc3068b4b8508.tar.gz bcm5719-llvm-e15605ccbf838770a495652215bfc3068b4b8508.zip |
add support for iterators.
llvm-svn: 34179
Diffstat (limited to 'llvm/lib/Support/StringMap.cpp')
-rw-r--r-- | llvm/lib/Support/StringMap.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp index 6eefd44c52f..d56d1da6647 100644 --- a/llvm/lib/Support/StringMap.cpp +++ b/llvm/lib/Support/StringMap.cpp @@ -25,8 +25,12 @@ StringMapImpl::StringMapImpl(unsigned InitSize, unsigned itemSize) { ItemSize = itemSize; NumItems = 0; - TheTable = new ItemBucket[NumBuckets](); + TheTable = new ItemBucket[NumBuckets+1](); memset(TheTable, 0, NumBuckets*sizeof(ItemBucket)); + + // Allocate one extra bucket, set it to look filled so the iterators stop at + // end. + TheTable[NumBuckets].Item = (StringMapEntryBase*)2; } @@ -94,8 +98,11 @@ unsigned StringMapImpl::LookupBucketFor(const char *NameStart, /// the appropriate mod-of-hashtable-size. void StringMapImpl::RehashTable() { unsigned NewSize = NumBuckets*2; - ItemBucket *NewTableArray = new ItemBucket[NewSize](); + // Allocate one extra bucket which will always be non-empty. This allows the + // iterators to stop at end. + ItemBucket *NewTableArray = new ItemBucket[NewSize+1](); memset(NewTableArray, 0, NewSize*sizeof(ItemBucket)); + NewTableArray[NewSize].Item = (StringMapEntryBase*)2; // Rehash all the items into their new buckets. Luckily :) we already have // the hash values available, so we don't have to rehash any strings. |