@@ -16277,7 +16277,7 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
1627716277 int capacity = table->Capacity();
1627816278 int nof = table->NumberOfElements() + n;
1627916279
16280- if (table->HasSufficientCapacity (n)) return table;
16280+ if (table->HasSufficientCapacityToAdd (n)) return table;
1628116281
1628216282 const int kMinCapacityForPretenure = 256;
1628316283 bool should_pretenure = pretenure == TENURED ||
@@ -16293,16 +16293,16 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
1629316293 return new_table;
1629416294}
1629516295
16296-
1629716296template <typename Derived, typename Shape, typename Key>
16298- bool HashTable<Derived, Shape, Key>::HasSufficientCapacity(int n) {
16297+ bool HashTable<Derived, Shape, Key>::HasSufficientCapacityToAdd(
16298+ int number_of_additional_elements) {
1629916299 int capacity = Capacity();
16300- int nof = NumberOfElements() + n ;
16300+ int nof = NumberOfElements() + number_of_additional_elements ;
1630116301 int nod = NumberOfDeletedElements();
1630216302 // Return true if:
16303- // 50% is still free after adding n elements and
16303+ // 50% is still free after adding number_of_additional_elements elements and
1630416304 // at most 50% of the free elements are deleted elements.
16305- if (nod <= (capacity - nof) >> 1) {
16305+ if ((nof < capacity) && (( nod <= (capacity - nof) >> 1)) ) {
1630616306 int needed_free = nof >> 1;
1630716307 if (nof + needed_free <= capacity) return true;
1630816308 }
@@ -17274,7 +17274,7 @@ void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() {
1727417274 DCHECK_EQ(0, DerivedHashTable::NumberOfDeletedElements());
1727517275 // Make sure that HashTable::EnsureCapacity will create a copy.
1727617276 DerivedHashTable::SetNumberOfDeletedElements(DerivedHashTable::Capacity());
17277- DCHECK(!DerivedHashTable::HasSufficientCapacity (1));
17277+ DCHECK(!DerivedHashTable::HasSufficientCapacityToAdd (1));
1727817278}
1727917279
1728017280
@@ -17694,8 +17694,8 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
1769417694 }
1769517695 // If we're out of luck, we didn't get a GC recently, and so rehashing
1769617696 // isn't enough to avoid a crash.
17697- int nof = table->NumberOfElements() + 1;
17698- if (! table->HasSufficientCapacity(nof)) {
17697+ if (! table->HasSufficientCapacityToAdd(1)) {
17698+ int nof = table->NumberOfElements() + 1;
1769917699 int capacity = ObjectHashTable::ComputeCapacity(nof * 2);
1770017700 if (capacity > ObjectHashTable::kMaxCapacity) {
1770117701 for (size_t i = 0; i < 2; ++i) {
0 commit comments