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

Chris Lattner sabre at nondot.org
Tue Jan 30 22:04:56 PST 2007



Changes in directory llvm/lib/Support:

FoldingSet.cpp updated: 1.12 -> 1.13
---
Log message:

minor cleanups.  Fix off-by-one in accounting the number of nodes when the
table grows.


---
Diffs of the changes:  (+5 -4)

 FoldingSet.cpp |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)


Index: llvm/lib/Support/FoldingSet.cpp
diff -u llvm/lib/Support/FoldingSet.cpp:1.12 llvm/lib/Support/FoldingSet.cpp:1.13
--- llvm/lib/Support/FoldingSet.cpp:1.12	Tue Jan 30 17:16:22 2007
+++ llvm/lib/Support/FoldingSet.cpp	Wed Jan 31 00:04:41 2007
@@ -181,7 +181,7 @@
   for (unsigned i = 0; i != OldNumBuckets; ++i) {
     void *Probe = OldBuckets[i];
     if (!Probe) continue;
-    while (Node *NodeInBucket = GetNextPtr(Probe, OldBuckets, OldNumBuckets)){
+    while (Node *NodeInBucket = GetNextPtr(Probe, OldBuckets, OldNumBuckets)) {
       // Figure out the next link, remove NodeInBucket from the old link.
       Probe = NodeInBucket->getNextInBucket();
       NodeInBucket->SetNextInBucket(0);
@@ -224,14 +224,15 @@
 /// is not already in the map.  InsertPos must be obtained from 
 /// FindNodeOrInsertPos.
 void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
-  ++NumNodes;
   // Do we need to grow the hashtable?
-  if (NumNodes > NumBuckets*2) {
+  if (NumNodes+1 > NumBuckets*2) {
     GrowHashTable();
     NodeID ID;
     GetNodeProfile(ID, N);
     InsertPos = GetBucketFor(ID, Buckets, NumBuckets);
   }
+
+  ++NumNodes;
   
   /// The insert position is actually a bucket pointer.
   void **Bucket = static_cast<void**>(InsertPos);
@@ -243,7 +244,7 @@
   if (Next == 0)
     Next = Bucket;
 
-  // Set the nodes next pointer, and make the bucket point to the node.
+  // Set the node's next pointer, and make the bucket point to the node.
   N->SetNextInBucket(Next);
   *Bucket = N;
 }






More information about the llvm-commits mailing list