aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-11 08:20:35 +0000
committerChris Lattner <sabre@nondot.org>2007-02-11 08:20:35 +0000
commita86559ec426c643a151aeba1e051e4f878050f95 (patch)
tree6d744c9e63345a6fa6c4106a4206b83a8cd35db4 /lib/Support
parent6ccadf6f7f196b6c27a0eb966a90b8c39812b780 (diff)
downloadexternal_llvm-a86559ec426c643a151aeba1e051e4f878050f95.zip
external_llvm-a86559ec426c643a151aeba1e051e4f878050f95.tar.gz
external_llvm-a86559ec426c643a151aeba1e051e4f878050f95.tar.bz2
add support for iterators.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34179 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/StringMap.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Support/StringMap.cpp b/lib/Support/StringMap.cpp
index 6eefd44..d56d1da 100644
--- a/lib/Support/StringMap.cpp
+++ b/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.