diff options
author | Dan Gohman <gohman@apple.com> | 2008-08-23 00:42:16 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2008-08-23 00:42:16 +0000 |
commit | 0e44e0d7a82b333fde0199283b85a3f94f2039e8 (patch) | |
tree | e26b9402d8b8fbca3674a3811d8fe6fbed682149 /llvm/lib/Support/FoldingSet.cpp | |
parent | 80a840bc70f4fcfc3b45fede0e701723d9eea914 (diff) | |
download | bcm5719-llvm-0e44e0d7a82b333fde0199283b85a3f94f2039e8.tar.gz bcm5719-llvm-0e44e0d7a82b333fde0199283b85a3f94f2039e8.zip |
Add a clear() method to FoldingSet.
llvm-svn: 55210
Diffstat (limited to 'llvm/lib/Support/FoldingSet.cpp')
-rw-r--r-- | llvm/lib/Support/FoldingSet.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/llvm/lib/Support/FoldingSet.cpp b/llvm/lib/Support/FoldingSet.cpp index 6966ec8a153..5a96dcd4485 100644 --- a/llvm/lib/Support/FoldingSet.cpp +++ b/llvm/lib/Support/FoldingSet.cpp @@ -200,19 +200,26 @@ static void **GetBucketFor(const FoldingSetNodeID &ID, //===----------------------------------------------------------------------===// // 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 @@ void FoldingSetImpl::GrowHashTable() { 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; |