deps: cherry-pick a76d133 from v8 upstream · nodejs/node@e22ffef

@@ -17389,7 +17389,7 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(

1738917389

int capacity = table->Capacity();

1739017390

int nof = table->NumberOfElements() + n;

173911739117392-

if (table->HasSufficientCapacity(n)) return table;

17392+

if (table->HasSufficientCapacityToAdd(n)) return table;

17393173931739417394

const int kMinCapacityForPretenure = 256;

1739517395

bool should_pretenure = pretenure == TENURED ||

@@ -17405,16 +17405,16 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(

1740517405

return new_table;

1740617406

}

174071740717408-1740917408

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) {

1741117411

int capacity = Capacity();

17412-

int nof = NumberOfElements() + n;

17412+

int nof = NumberOfElements() + number_of_additional_elements;

1741317413

int nod = NumberOfDeletedElements();

1741417414

// 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

1741617416

// at most 50% of the free elements are deleted elements.

17417-

if (nod <= (capacity - nof) >> 1) {

17417+

if ((nof < capacity) && ((nod <= (capacity - nof) >> 1))) {

1741817418

int needed_free = nof >> 1;

1741917419

if (nof + needed_free <= capacity) return true;

1742017420

}

@@ -18332,7 +18332,7 @@ void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() {

1833218332

DCHECK_EQ(0, DerivedHashTable::NumberOfDeletedElements());

1833318333

// Make sure that HashTable::EnsureCapacity will create a copy.

1833418334

DerivedHashTable::SetNumberOfDeletedElements(DerivedHashTable::Capacity());

18335-

DCHECK(!DerivedHashTable::HasSufficientCapacity(1));

18335+

DCHECK(!DerivedHashTable::HasSufficientCapacityToAdd(1));

1833618336

}

18337183371833818338

@@ -18742,8 +18742,8 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,

1874218742

}

1874318743

// If we're out of luck, we didn't get a GC recently, and so rehashing

1874418744

// 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;

1874718747

int capacity = ObjectHashTable::ComputeCapacity(nof * 2);

1874818748

if (capacity > ObjectHashTable::kMaxCapacity) {

1874918749

for (size_t i = 0; i < 2; ++i) {