@@ -17389,7 +17389,7 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
17389
17389
int capacity = table->Capacity();
17390
17390
int nof = table->NumberOfElements() + n;
17391
17391
17392
- if (table->HasSufficientCapacity (n)) return table;
17392
+ if (table->HasSufficientCapacityToAdd (n)) return table;
17393
17393
17394
17394
const int kMinCapacityForPretenure = 256;
17395
17395
bool should_pretenure = pretenure == TENURED ||
@@ -17405,16 +17405,16 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
17405
17405
return new_table;
17406
17406
}
17407
17407
17408
-
17409
17408
template <typename Derived, typename Shape, typename Key>
17410
- bool HashTable<Derived, Shape, Key>::HasSufficientCapacity(int n) {
17409
+ bool HashTable<Derived, Shape, Key>::HasSufficientCapacityToAdd(
17410
+ int number_of_additional_elements) {
17411
17411
int capacity = Capacity();
17412
- int nof = NumberOfElements() + n ;
17412
+ int nof = NumberOfElements() + number_of_additional_elements ;
17413
17413
int nod = NumberOfDeletedElements();
17414
17414
// Return true if:
17415
- // 50% is still free after adding n elements and
17415
+ // 50% is still free after adding number_of_additional_elements elements and
17416
17416
// at most 50% of the free elements are deleted elements.
17417
- if (nod <= (capacity - nof) >> 1) {
17417
+ if ((nof < capacity) && (( nod <= (capacity - nof) >> 1)) ) {
17418
17418
int needed_free = nof >> 1;
17419
17419
if (nof + needed_free <= capacity) return true;
17420
17420
}
@@ -18332,7 +18332,7 @@ void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() {
18332
18332
DCHECK_EQ(0, DerivedHashTable::NumberOfDeletedElements());
18333
18333
// Make sure that HashTable::EnsureCapacity will create a copy.
18334
18334
DerivedHashTable::SetNumberOfDeletedElements(DerivedHashTable::Capacity());
18335
- DCHECK(!DerivedHashTable::HasSufficientCapacity (1));
18335
+ DCHECK(!DerivedHashTable::HasSufficientCapacityToAdd (1));
18336
18336
}
18337
18337
18338
18338
@@ -18742,8 +18742,8 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
18742
18742
}
18743
18743
// If we're out of luck, we didn't get a GC recently, and so rehashing
18744
18744
// isn't enough to avoid a crash.
18745
- int nof = table->NumberOfElements() + 1;
18746
- if (! table->HasSufficientCapacity(nof)) {
18745
+ if (! table->HasSufficientCapacityToAdd(1)) {
18746
+ int nof = table->NumberOfElements() + 1;
18747
18747
int capacity = ObjectHashTable::ComputeCapacity(nof * 2);
18748
18748
if (capacity > ObjectHashTable::kMaxCapacity) {
18749
18749
for (size_t i = 0; i < 2; ++i) {
0 commit comments