Allow FoldingSet clients to pump up the initial hash size.
authorJim Laskey <jlaskey@mac.com>
Thu, 2 Nov 2006 14:21:26 +0000 (14:21 +0000)
committerJim Laskey <jlaskey@mac.com>
Thu, 2 Nov 2006 14:21:26 +0000 (14:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31377 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/FoldingSet.h
lib/Support/FoldingSet.cpp

index 6b0463365a223b5fdfc4b8070f52b08d9a614c00..1a9407108f0d494b35ceb34844da1f770fde8bd0 100644 (file)
@@ -117,7 +117,7 @@ private:
   unsigned NumNodes;
   
 public:
-  FoldingSetImpl();
+  FoldingSetImpl(unsigned Log2InitSize = 6);
   virtual ~FoldingSetImpl();
   
   // Forward declaration.
@@ -229,6 +229,10 @@ private:
   }
   
 public:
+  FoldingSet(unsigned Log2InitSize = 6)
+  : FoldingSetImpl(Log2InitSize)
+  {}
+
   /// GetOrInsertNode - If there is an existing simple Node exactly
   /// equal to the specified node, return it.  Otherwise, insert 'N' and
   /// return it instead.
index 1bd20145f45ca2d244c675bde71ae6b2655ff07c..a569e1a79d2ff9bee1a6cc5fb53df4ec6a6f96c5 100644 (file)
@@ -151,8 +151,10 @@ static void **GetBucketFor(const FoldingSetImpl::NodeID &ID,
 //===----------------------------------------------------------------------===//
 // FoldingSetImpl Implementation
 
-FoldingSetImpl::FoldingSetImpl() : NumNodes(0) {
-  NumBuckets = 64;
+FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) : NumNodes(0) {
+  assert(5 < Log2InitSize && Log2InitSize < 32 &&
+         "Initial hash table size out of range");
+  NumBuckets = 1 << Log2InitSize;
   Buckets = new void*[NumBuckets];
   memset(Buckets, 0, NumBuckets*sizeof(void*));
 }