@@ -6677,7 +6677,7 @@ void StringTable::EnsureCapacityForDeserialization(Isolate* isolate,
66776677 int expected) {
66786678 Handle<StringTable> table = isolate->factory ()->string_table ();
66796679 // We need a key instance for the virtual hash function.
6680- table = StringTable:: EnsureCapacity (isolate, table, expected);
6680+ table = EnsureCapacity (isolate, table, expected);
66816681 isolate->heap ()->SetRootStringTable (*table);
66826682}
66836683
@@ -6729,7 +6729,7 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, StringTableKey* key) {
67296729
67306730 table = StringTable::CautiousShrink (isolate, table);
67316731 // Adding new string. Grow table if needed.
6732- table = StringTable:: EnsureCapacity (isolate, table, 1 );
6732+ table = EnsureCapacity (isolate, table);
67336733 isolate->heap ()->SetRootStringTable (*table);
67346734
67356735 return AddKeyNoResize (isolate, key);
@@ -6870,7 +6870,7 @@ Handle<StringSet> StringSet::New(Isolate* isolate) {
68706870Handle<StringSet> StringSet::Add (Isolate* isolate, Handle<StringSet> stringset,
68716871 Handle<String> name) {
68726872 if (!stringset->Has (isolate, name)) {
6873- stringset = EnsureCapacity (isolate, stringset, 1 );
6873+ stringset = EnsureCapacity (isolate, stringset);
68746874 uint32_t hash = ShapeT::Hash (isolate, *name);
68756875 int entry = stringset->FindInsertionEntry (hash);
68766876 stringset->set (EntryToIndex (entry), *name);
@@ -6888,7 +6888,7 @@ Handle<ObjectHashSet> ObjectHashSet::Add(Isolate* isolate,
68886888 Handle<Object> key) {
68896889 int32_t hash = key->GetOrCreateHash (isolate).value ();
68906890 if (!set->Has (isolate, key, hash)) {
6891- set = EnsureCapacity (isolate, set, 1 );
6891+ set = EnsureCapacity (isolate, set);
68926892 int entry = set->FindInsertionEntry (hash);
68936893 set->set (EntryToIndex (entry), *key);
68946894 set->ElementAdded ();
@@ -7084,7 +7084,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutScript(
70847084 src = String::Flatten (isolate, src);
70857085 StringSharedKey key (src, shared, language_mode, kNoSourcePosition );
70867086 Handle<Object> k = key.AsHandle (isolate);
7087- cache = EnsureCapacity (isolate, cache, 1 );
7087+ cache = EnsureCapacity (isolate, cache);
70887088 int entry = cache->FindInsertionEntry (key.Hash ());
70897089 cache->set (EntryToIndex (entry), *k);
70907090 cache->set (EntryToIndex (entry) + 1 , *value);
@@ -7116,7 +7116,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
71167116 }
71177117 }
71187118
7119- cache = EnsureCapacity (isolate, cache, 1 );
7119+ cache = EnsureCapacity (isolate, cache);
71207120 int entry = cache->FindInsertionEntry (key.Hash ());
71217121 Handle<Object> k =
71227122 isolate->factory ()->NewNumber (static_cast <double >(key.Hash ()));
@@ -7130,7 +7130,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
71307130 Isolate* isolate, Handle<CompilationCacheTable> cache, Handle<String> src,
71317131 JSRegExp::Flags flags, Handle<FixedArray> value) {
71327132 RegExpKey key (src, flags);
7133- cache = EnsureCapacity (isolate, cache, 1 );
7133+ cache = EnsureCapacity (isolate, cache);
71347134 int entry = cache->FindInsertionEntry (key.Hash ());
71357135 // We store the value in the key slot, and compare the search key
71367136 // to the stored value with a custon IsMatch function during lookups.
@@ -7192,15 +7192,16 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::New(
71927192 Handle<Derived> dict = Dictionary<Derived, Shape>::New (
71937193 isolate, at_least_space_for, allocation, capacity_option);
71947194 dict->SetHash (PropertyArray::kNoHashSentinel );
7195- dict->SetNextEnumerationIndex (PropertyDetails::kInitialIndex );
7195+ dict->set_next_enumeration_index (PropertyDetails::kInitialIndex );
71967196 return dict;
71977197}
71987198
71997199template <typename Derived, typename Shape>
7200- Handle<Derived> BaseNameDictionary<Derived, Shape>::EnsureCapacity(
7201- Isolate* isolate, Handle<Derived> dictionary, int n) {
7202- // Check whether there are enough enumeration indices to add n elements.
7203- if (!PropertyDetails::IsValidIndex (dictionary->NextEnumerationIndex () + n)) {
7200+ int BaseNameDictionary<Derived, Shape>::NextEnumerationIndex(
7201+ Isolate* isolate, Handle<Derived> dictionary) {
7202+ int index = dictionary->next_enumeration_index ();
7203+ // Check whether the next enumeration index is valid.
7204+ if (!PropertyDetails::IsValidIndex (index)) {
72047205 // If not, we generate new indices for the properties.
72057206 int length = dictionary->NumberOfElements ();
72067207
@@ -7221,11 +7222,12 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::EnsureCapacity(
72217222 dictionary->DetailsAtPut (isolate, index, new_details);
72227223 }
72237224
7224- // Set the next enumeration index.
7225- dictionary->SetNextEnumerationIndex (PropertyDetails::kInitialIndex +
7226- length);
7225+ index = PropertyDetails::kInitialIndex + length;
72277226 }
7228- return HashTable<Derived, Shape>::EnsureCapacity (isolate, dictionary, n);
7227+
7228+ // Don't update the next enumeration index here, since we might be looking at
7229+ // an immutable empty dictionary.
7230+ return index;
72297231}
72307232
72317233template <typename Derived, typename Shape>
@@ -7274,13 +7276,13 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::Add(
72747276 DCHECK_EQ (0 , details.dictionary_index ());
72757277 // Assign an enumeration index to the property and update
72767278 // SetNextEnumerationIndex.
7277- int index = dictionary-> NextEnumerationIndex ();
7279+ int index = Derived:: NextEnumerationIndex (isolate, dictionary );
72787280 details = details.set_index (index);
72797281 dictionary = AddNoUpdateNextEnumerationIndex (isolate, dictionary, key, value,
72807282 details, entry_out);
72817283 // Update enumeration index here in order to avoid potential modification of
72827284 // the canonical empty dictionary which lives in read only space.
7283- dictionary->SetNextEnumerationIndex (index + 1 );
7285+ dictionary->set_next_enumeration_index (index + 1 );
72847286 return dictionary;
72857287}
72867288
@@ -7294,7 +7296,7 @@ Handle<Derived> Dictionary<Derived, Shape>::Add(Isolate* isolate,
72947296 // Valdate key is absent.
72957297 SLOW_DCHECK ((dictionary->FindEntry (isolate, key) == Dictionary::kNotFound ));
72967298 // Check whether the dictionary should be extended.
7297- dictionary = Derived::EnsureCapacity (isolate, dictionary, 1 );
7299+ dictionary = Derived::EnsureCapacity (isolate, dictionary);
72987300
72997301 // Compute the key object.
73007302 Handle<Object> k = Shape::AsHandle (isolate, key);
@@ -7644,7 +7646,7 @@ Handle<Derived> ObjectHashTableBase<Derived, Shape>::Put(Isolate* isolate,
76447646 }
76457647
76467648 // Check whether the hash table should be extended.
7647- table = Derived::EnsureCapacity (isolate, table, 1 );
7649+ table = Derived::EnsureCapacity (isolate, table);
76487650 table->AddEntry (table->FindInsertionEntry (hash), *key, *value);
76497651 return table;
76507652}
@@ -7892,8 +7894,8 @@ Handle<PropertyCell> PropertyCell::PrepareForValue(
78927894 // Preserve the enumeration index unless the property was deleted or never
78937895 // initialized.
78947896 if (cell->value ().IsTheHole (isolate)) {
7895- index = dictionary-> NextEnumerationIndex ();
7896- dictionary->SetNextEnumerationIndex (index + 1 );
7897+ index = GlobalDictionary:: NextEnumerationIndex (isolate, dictionary );
7898+ dictionary->set_next_enumeration_index (index + 1 );
78977899 } else {
78987900 index = original_details.dictionary_index ();
78997901 }
0 commit comments