summaryrefslogtreecommitdiff
path: root/lib/Support/FoldingSet.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-01-31 06:04:41 +0000
committerChris Lattner <sabre@nondot.org>2007-01-31 06:04:41 +0000
commitb85210f508556a81aecde07b87b2dfc6236de6e7 (patch)
tree8c8ac02f5e410e64307ad370a086b780489476f4 /lib/Support/FoldingSet.cpp
parent033152455558d643f382b64e9d443ceb8d8702ff (diff)
downloadllvm-b85210f508556a81aecde07b87b2dfc6236de6e7.tar.gz
llvm-b85210f508556a81aecde07b87b2dfc6236de6e7.tar.bz2
llvm-b85210f508556a81aecde07b87b2dfc6236de6e7.tar.xz
minor cleanups. Fix off-by-one in accounting the number of nodes when the
table grows. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33698 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/FoldingSet.cpp')
-rw-r--r--lib/Support/FoldingSet.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/Support/FoldingSet.cpp b/lib/Support/FoldingSet.cpp
index 716fe99b52..dbf3a583d8 100644
--- a/lib/Support/FoldingSet.cpp
+++ b/lib/Support/FoldingSet.cpp
@@ -181,7 +181,7 @@ void FoldingSetImpl::GrowHashTable() {
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 @@ FoldingSetImpl::Node *FoldingSetImpl::FindNodeOrInsertPos(const NodeID &ID,
/// 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 @@ void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
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;
}