From bb0a822b3e205513498838b66073092309dac926 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sun, 30 Oct 2011 16:12:48 -0700 Subject: [PATCH] Bug 697933 - Allow HashTables to have a capacity as small as four. r=luke. --- js/public/HashTable.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/js/public/HashTable.h b/js/public/HashTable.h index f60014766c3b..918093c7e53c 100644 --- a/js/public/HashTable.h +++ b/js/public/HashTable.h @@ -295,8 +295,13 @@ class HashTable : private AllocPolicy uint64 mutationCount; #endif - static const unsigned sMinSizeLog2 = 4; + /* The default initial capacity is 16, but you can ask for as small as 4. */ + static const unsigned sMinSizeLog2 = 2; static const unsigned sMinSize = 1 << sMinSizeLog2; + static const unsigned sDefaultInitSizeLog2 = 4; + public: + static const unsigned sDefaultInitSize = 1 << sDefaultInitSizeLog2; + private: static const unsigned sMaxInit = JS_BIT(23); static const unsigned sMaxCapacity = JS_BIT(24); static const unsigned sHashBits = tl::BitSize::result; @@ -986,7 +991,7 @@ class HashMap * init after constructing a HashMap and check the return value. */ HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} - bool init(uint32 len = 0) { return impl.init(len); } + bool init(uint32 len = Impl::sDefaultInitSize) { return impl.init(len); } bool initialized() const { return impl.initialized(); } /* @@ -1214,7 +1219,7 @@ class HashSet * init after constructing a HashSet and check the return value. */ HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} - bool init(uint32 len = 0) { return impl.init(len); } + bool init(uint32 len = Impl::sDefaultInitSize) { return impl.init(len); } bool initialized() const { return impl.initialized(); } /*