Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index dff101c54e0c2ec8573e43e818f7b60a263c1b66..673a70854b123098854507df080ba62bcdfeca7d 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -17159,14 +17159,8 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( |
Isolate* isolate = table->GetIsolate(); |
int capacity = table->Capacity(); |
int nof = table->NumberOfElements() + n; |
- int nod = table->NumberOfDeletedElements(); |
- // Return if: |
- // 50% is still free after adding n elements and |
- // at most 50% of the free elements are deleted elements. |
- if (nod <= (capacity - nof) >> 1) { |
- int needed_free = nof >> 1; |
- if (nof + needed_free <= capacity) return table; |
- } |
+ |
+ if (table->HasSufficientCapacity(n)) return table; |
const int kMinCapacityForPretenure = 256; |
bool should_pretenure = pretenure == TENURED || |
@@ -17183,6 +17177,22 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( |
} |
+template <typename Derived, typename Shape, typename Key> |
+bool HashTable<Derived, Shape, Key>::HasSufficientCapacity(int n) { |
+ int capacity = Capacity(); |
+ int nof = NumberOfElements() + n; |
+ int nod = NumberOfDeletedElements(); |
+ // Return true if: |
+ // 50% is still free after adding n elements and |
+ // at most 50% of the free elements are deleted elements. |
+ if (nod <= (capacity - nof) >> 1) { |
+ int needed_free = nof >> 1; |
+ if (nof + needed_free <= capacity) return true; |
+ } |
+ return false; |
+} |
+ |
+ |
template<typename Derived, typename Shape, typename Key> |
Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table, |
Key key) { |
@@ -17349,6 +17359,9 @@ template Handle<UnseededNumberDictionary> |
Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>:: |
EnsureCapacity(Handle<UnseededNumberDictionary>, int, uint32_t); |
+template void Dictionary<NameDictionary, NameDictionaryShape, |
+ Handle<Name> >::SetRequiresCopyOnCapacityChange(); |
+ |
template Handle<NameDictionary> |
Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >:: |
EnsureCapacity(Handle<NameDictionary>, int, Handle<Name>); |
@@ -18077,7 +18090,17 @@ Dictionary<Derived, Shape, Key>::GenerateNewEnumerationIndices( |
} |
-template<typename Derived, typename Shape, typename Key> |
+template <typename Derived, typename Shape, typename Key> |
+void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() { |
+ DCHECK_EQ(0, DerivedHashTable::NumberOfElements()); |
+ DCHECK_EQ(0, DerivedHashTable::NumberOfDeletedElements()); |
+ // Make sure that HashTable::EnsureCapacity will create a copy. |
+ DerivedHashTable::SetNumberOfDeletedElements(DerivedHashTable::Capacity()); |
+ DCHECK(!DerivedHashTable::HasSufficientCapacity(1)); |
+} |
+ |
+ |
+template <typename Derived, typename Shape, typename Key> |
Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity( |
Handle<Derived> dictionary, int n, Key key) { |
// Check whether there are enough enumeration indices to add n elements. |