Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: test/unittests/object-unittest.cc

Issue 2827263004: Fix HashTable growth strategy to be 2x instead of 4x (Closed)
Patch Set: update CSA; fix test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/ensure-growing-store-learns.js ('k') | tools/dev/gm.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/object-unittest.cc
diff --git a/test/unittests/object-unittest.cc b/test/unittests/object-unittest.cc
index b09b97dea6991f2ee23651bd58d2a20137982798..e0a65f2ac86eb063c2ff48a7796bd4b0c6760092 100644
--- a/test/unittests/object-unittest.cc
+++ b/test/unittests/object-unittest.cc
@@ -8,6 +8,7 @@
#include "src/objects-inl.h"
#include "src/objects.h"
+#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -53,5 +54,64 @@ TEST(Object, StructListOrder) {
#undef TEST_STRUCT
}
+typedef TestWithIsolate ObjectWithIsolate;
+
+TEST_F(ObjectWithIsolate, DictionaryGrowth) {
+ Handle<SeededNumberDictionary> dict =
+ SeededNumberDictionary::New(isolate(), 1);
+ Handle<Object> value = isolate()->factory()->null_value();
+ PropertyDetails details = PropertyDetails::Empty();
+
+ // This test documents the expected growth behavior of a dictionary getting
+ // elements added to it one by one.
+ STATIC_ASSERT(HashTableBase::kMinCapacity == 4);
+ uint32_t i = 1;
+ // 3 elements fit into the initial capacity.
+ for (; i <= 3; i++) {
+ dict = SeededNumberDictionary::Add(dict, i, value, details);
+ CHECK_EQ(4, dict->Capacity());
+ }
+ // 4th element triggers growth.
+ DCHECK_EQ(4, i);
+ for (; i <= 5; i++) {
+ dict = SeededNumberDictionary::Add(dict, i, value, details);
+ CHECK_EQ(8, dict->Capacity());
+ }
+ // 6th element triggers growth.
+ DCHECK_EQ(6, i);
+ for (; i <= 11; i++) {
+ dict = SeededNumberDictionary::Add(dict, i, value, details);
+ CHECK_EQ(16, dict->Capacity());
+ }
+ // 12th element triggers growth.
+ DCHECK_EQ(12, i);
+ for (; i <= 21; i++) {
+ dict = SeededNumberDictionary::Add(dict, i, value, details);
+ CHECK_EQ(32, dict->Capacity());
+ }
+ // 22nd element triggers growth.
+ DCHECK_EQ(22, i);
+ for (; i <= 43; i++) {
+ dict = SeededNumberDictionary::Add(dict, i, value, details);
+ CHECK_EQ(64, dict->Capacity());
+ }
+ // 44th element triggers growth.
+ DCHECK_EQ(44, i);
+ for (; i <= 50; i++) {
+ dict = SeededNumberDictionary::Add(dict, i, value, details);
+ CHECK_EQ(128, dict->Capacity());
+ }
+
+ // If we grow by larger chunks, the next (sufficiently big) power of 2 is
+ // chosen as the capacity.
+ dict = SeededNumberDictionary::New(isolate(), 1);
+ dict = SeededNumberDictionary::EnsureCapacity(dict, 65, 1);
+ CHECK_EQ(128, dict->Capacity());
+
+ dict = SeededNumberDictionary::New(isolate(), 1);
+ dict = SeededNumberDictionary::EnsureCapacity(dict, 30, 1);
+ CHECK_EQ(64, dict->Capacity());
+}
+
} // namespace internal
} // namespace v8
« no previous file with comments | « test/mjsunit/ensure-growing-store-learns.js ('k') | tools/dev/gm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698