summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-08-23 00:42:16 +0000
committerDan Gohman <gohman@apple.com>2008-08-23 00:42:16 +0000
commit535de1a8c14fdfeb3912d3192accb58d9aa1e9e7 (patch)
tree9d3788d9079d0f364e8fee711ba3262aebdd97b9 /lib/Support
parent169b5ed46e969ad2b04efeac54bd24a316c14e05 (diff)
downloadllvm-535de1a8c14fdfeb3912d3192accb58d9aa1e9e7.tar.gz
llvm-535de1a8c14fdfeb3912d3192accb58d9aa1e9e7.tar.bz2
llvm-535de1a8c14fdfeb3912d3192accb58d9aa1e9e7.tar.xz
Add a clear() method to FoldingSet.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55210 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/FoldingSet.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/Support/FoldingSet.cpp b/lib/Support/FoldingSet.cpp
index 6966ec8a15..5a96dcd448 100644
--- a/lib/Support/FoldingSet.cpp
+++ b/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;