| Index: src/objects.cc
|
| diff --git a/src/objects.cc b/src/objects.cc
|
| index 697c1d3840f8aa301d07591019a49689f431d361..c948b49d3ede8ec487f5ca3d6338786817c1868a 100644
|
| --- a/src/objects.cc
|
| +++ b/src/objects.cc
|
| @@ -17186,14 +17186,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 ||
|
| @@ -17210,6 +17204,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) {
|
| @@ -17376,6 +17386,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>);
|
| @@ -18104,7 +18117,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.
|
|
|