[llvm-commits] CVS: llvm/lib/Support/StringMap.cpp

Chris Lattner sabre at nondot.org
Sun Feb 11 00:21:06 PST 2007



Changes in directory llvm/lib/Support:

StringMap.cpp updated: 1.5 -> 1.6
---
Log message:

add support for iterators.


---
Diffs of the changes:  (+9 -2)

 StringMap.cpp |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)


Index: llvm/lib/Support/StringMap.cpp
diff -u llvm/lib/Support/StringMap.cpp:1.5 llvm/lib/Support/StringMap.cpp:1.6
--- llvm/lib/Support/StringMap.cpp:1.5	Thu Feb  8 13:20:57 2007
+++ llvm/lib/Support/StringMap.cpp	Sun Feb 11 02:20:35 2007
@@ -25,8 +25,12 @@
   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 @@
 /// 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.






More information about the llvm-commits mailing list