aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/FoldingSet.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-01 05:33:21 +0000
committerChris Lattner <sabre@nondot.org>2007-02-01 05:33:21 +0000
commit4f5cdecde3bf7e9f4a19ca44e0cfbdafe1b4c469 (patch)
treec680dd3c2823dd83a94f500d79dbbad5b5689cb7 /llvm/lib/Support/FoldingSet.cpp
parent1003dc72b419592946c1b74b4cb26bceeeecdea9 (diff)
downloadllvm-4f5cdecde3bf7e9f4a19ca44e0cfbdafe1b4c469.zip
llvm-4f5cdecde3bf7e9f4a19ca44e0cfbdafe1b4c469.tar.gz
llvm-4f5cdecde3bf7e9f4a19ca44e0cfbdafe1b4c469.tar.bz2
improve comments, add an assertion
llvm-svn: 33750
Diffstat (limited to 'llvm/lib/Support/FoldingSet.cpp')
-rw-r--r--llvm/lib/Support/FoldingSet.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Support/FoldingSet.cpp b/llvm/lib/Support/FoldingSet.cpp
index 1d04abf..1b0e81e 100644
--- a/llvm/lib/Support/FoldingSet.cpp
+++ b/llvm/lib/Support/FoldingSet.cpp
@@ -226,6 +226,7 @@ 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) {
+ assert(N->getNextInBucket() == 0);
// Do we need to grow the hashtable?
DEBUG(DOUT << "INSERT: " << N << '\n');
if (NumNodes+1 > NumBuckets*2) {
@@ -256,16 +257,18 @@ void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
/// removed or false if the node was not in the folding set.
bool FoldingSetImpl::RemoveNode(Node *N) {
// Because each bucket is a circular list, we don't need to compute N's hash
- // to remove it. Chase around the list until we find the node (or bucket)
- // which points to N.
+ // to remove it.
DEBUG(DOUT << "REMOVE: " << N << '\n');
void *Ptr = N->getNextInBucket();
if (Ptr == 0) return false; // Not in folding set.
--NumNodes;
+ N->SetNextInBucket(0);
+ // Remember what N originally pointed to, either a bucket or another node.
void *NodeNextPtr = Ptr;
- N->SetNextInBucket(0);
+
+ // Chase around the list until we find the node (or bucket) which points to N.
while (true) {
if (Node *NodeInBucket = GetNextPtr(Ptr, Buckets, NumBuckets)) {
// Advance pointer.