From: Benjamin Kramer Date: Sat, 19 Jun 2010 17:00:31 +0000 (+0000) Subject: Use calloc instead of new/memset, it is more efficient when the set is very large. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6118efa59ea751cb0790de860721695f5da819c1;p=oota-llvm.git Use calloc instead of new/memset, it is more efficient when the set is very large. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106390 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/FoldingSet.cpp b/lib/Support/FoldingSet.cpp index 3f467fe1b69..b8dca334da4 100644 --- a/lib/Support/FoldingSet.cpp +++ b/lib/Support/FoldingSet.cpp @@ -175,6 +175,14 @@ static void **GetBucketFor(const FoldingSetNodeID &ID, return Buckets + BucketNum; } +/// AllocateBuckets - Allocated initialized bucket memory. +static void **AllocateBuckets(unsigned NumBuckets) { + void **Buckets = static_cast(calloc(NumBuckets+1, sizeof(void*))); + // Set the very last bucket to be a non-null "pointer". + Buckets[NumBuckets] = reinterpret_cast(-1); + return Buckets; +} + //===----------------------------------------------------------------------===// // FoldingSetImpl Implementation @@ -182,11 +190,11 @@ FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) { assert(5 < Log2InitSize && Log2InitSize < 32 && "Initial hash table size out of range"); NumBuckets = 1 << Log2InitSize; - Buckets = new void*[NumBuckets+1]; - clear(); + Buckets = AllocateBuckets(NumBuckets); + NumNodes = 0; } FoldingSetImpl::~FoldingSetImpl() { - delete [] Buckets; + free(Buckets); } void FoldingSetImpl::clear() { // Set all but the last bucket to null pointers. @@ -207,8 +215,8 @@ void FoldingSetImpl::GrowHashTable() { NumBuckets <<= 1; // Clear out new buckets. - Buckets = new void*[NumBuckets+1]; - clear(); + Buckets = AllocateBuckets(NumBuckets); + NumNodes = 0; // Walk the old buckets, rehashing nodes into their new place. FoldingSetNodeID ID; @@ -227,7 +235,7 @@ void FoldingSetImpl::GrowHashTable() { } } - delete[] OldBuckets; + free(OldBuckets); } /// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,