[llvm-commits] [llvm] r55210 - in /llvm/trunk: include/llvm/ADT/FoldingSet.h lib/Support/FoldingSet.cpp
Chris Lattner
clattner at apple.com
Fri Aug 22 18:07:41 PDT 2008
On Aug 22, 2008, at 5:42 PM, Dan Gohman wrote:
> Author: djg
> Date: Fri Aug 22 19:42:16 2008
> New Revision: 55210
>
> URL: http://llvm.org/viewvc/llvm-project?rev=55210&view=rev
> Log:
> Add a clear() method to FoldingSet.
Does this delete the nodes in the folding set?
-Chris
>
>
> Modified:
> llvm/trunk/include/llvm/ADT/FoldingSet.h
> llvm/trunk/lib/Support/FoldingSet.cpp
>
> Modified: llvm/trunk/include/llvm/ADT/FoldingSet.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/FoldingSet.h?rev=55210&r1=55209&r2=55210&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/include/llvm/ADT/FoldingSet.h (original)
> +++ llvm/trunk/include/llvm/ADT/FoldingSet.h Fri Aug 22 19:42:16 2008
> @@ -143,6 +143,9 @@
> void SetNextInBucket(void *N) { NextInFoldingSetBucket = N; }
> };
>
> + /// clear - Remove all nodes from the folding set.
> + void clear();
> +
> /// RemoveNode - Remove a node from the folding set, returning
> true if one
> /// was removed or false if the node was not in the folding set.
> bool RemoveNode(Node *N);
>
> Modified: llvm/trunk/lib/Support/FoldingSet.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FoldingSet.cpp?rev=55210&r1=55209&r2=55210&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/Support/FoldingSet.cpp (original)
> +++ llvm/trunk/lib/Support/FoldingSet.cpp Fri Aug 22 19:42:16 2008
> @@ -200,19 +200,26 @@
> //
> =
> =
> =
> ----------------------------------------------------------------------=
> ==//
> // FoldingSetImpl Implementation
>
> -FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) : NumNodes(0) {
> +FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) {
> assert(5 < Log2InitSize && Log2InitSize < 32 &&
> "Initial hash table size out of range");
> NumBuckets = 1 << Log2InitSize;
> Buckets = new void*[NumBuckets+1];
> - memset(Buckets, 0, NumBuckets*sizeof(void*));
> -
> - // Set the very last bucket to be a non-null "pointer".
> - Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
> + clear();
> }
> FoldingSetImpl::~FoldingSetImpl() {
> delete [] Buckets;
> }
> +void FoldingSetImpl::clear() {
> + // Set all but the last bucket to null pointers.
> + memset(Buckets, 0, NumBuckets*sizeof(void*));
> +
> + // Set the very last bucket to be a non-null "pointer".
> + Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
> +
> + // Reset the node count to zero.
> + NumNodes = 0;
> +}
>
> /// GrowHashTable - Double the size of the hash table and rehash
> everything.
> ///
> @@ -221,15 +228,9 @@
> unsigned OldNumBuckets = NumBuckets;
> NumBuckets <<= 1;
>
> - // Reset the node count to zero: we're going to reinsert
> everything.
> - NumNodes = 0;
> -
> // Clear out new buckets.
> Buckets = new void*[NumBuckets+1];
> - memset(Buckets, 0, NumBuckets*sizeof(void*));
> -
> - // Set the very last bucket to be a non-null "pointer".
> - Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
> + clear();
>
> // Walk the old buckets, rehashing nodes into their new place.
> FoldingSetNodeID ID;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list