Give ComputeCapacityForSerialization a minimum capacity
authoradamk <adamk@chromium.org>
Fri, 8 May 2015 15:03:35 +0000 (08:03 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 8 May 2015 15:03:34 +0000 (15:03 +0000)
This avoids DCHECK failures when passing 0 as the at_least_space_for
argument to HashTableBase::New (allowing converting code from non-serialized
to serialized without changing callsites).

Review URL: https://codereview.chromium.org/1134573002

Cr-Commit-Position: refs/heads/master@{#28321}

src/heap/heap.cc
src/objects-inl.h

index 1e0f21c..54a8915 100644 (file)
@@ -3116,7 +3116,7 @@ void Heap::CreateInitialObjects() {
                           TENURED));
 
   Handle<SeededNumberDictionary> slow_element_dictionary =
-      SeededNumberDictionary::New(isolate(), 1, TENURED);
+      SeededNumberDictionary::New(isolate(), 0, TENURED);
   slow_element_dictionary->set_requires_slow_elements();
   set_empty_slow_element_dictionary(*slow_element_dictionary);
 
index 1abe0c1..cc264f6 100644 (file)
@@ -3260,15 +3260,14 @@ DescriptorArray::WhitenessWitness::~WhitenessWitness() {
 int HashTableBase::ComputeCapacity(int at_least_space_for) {
   const int kMinCapacity = 4;
   int capacity = base::bits::RoundUpToPowerOfTwo32(at_least_space_for * 2);
-  if (capacity < kMinCapacity) {
-    capacity = kMinCapacity;  // Guarantee min capacity.
-  }
-  return capacity;
+  return Max(capacity, kMinCapacity);
 }
 
 
 int HashTableBase::ComputeCapacityForSerialization(int at_least_space_for) {
-  return base::bits::RoundUpToPowerOfTwo32(at_least_space_for);
+  const int kMinCapacity = 1;
+  int capacity = base::bits::RoundUpToPowerOfTwo32(at_least_space_for);
+  return Max(capacity, kMinCapacity);
 }