@@ -6663,7 +6663,7 @@ void StringTable::EnsureCapacityForDeserialization(Isolate* isolate,
66636663 int expected) {
66646664 Handle<StringTable> table = isolate->factory ()->string_table ();
66656665 // We need a key instance for the virtual hash function.
6666- table = StringTable:: EnsureCapacity (isolate, table, expected);
6666+ table = EnsureCapacity (isolate, table, expected);
66676667 isolate->heap ()->SetRootStringTable (*table);
66686668}
66696669
@@ -6715,7 +6715,7 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, StringTableKey* key) {
67156715
67166716 table = StringTable::CautiousShrink (isolate, table);
67176717 // Adding new string. Grow table if needed.
6718- table = StringTable:: EnsureCapacity (isolate, table, 1 );
6718+ table = EnsureCapacity (isolate, table);
67196719 isolate->heap ()->SetRootStringTable (*table);
67206720
67216721 return AddKeyNoResize (isolate, key);
@@ -6856,7 +6856,7 @@ Handle<StringSet> StringSet::New(Isolate* isolate) {
68566856Handle<StringSet> StringSet::Add (Isolate* isolate, Handle<StringSet> stringset,
68576857 Handle<String> name) {
68586858 if (!stringset->Has (isolate, name)) {
6859- stringset = EnsureCapacity (isolate, stringset, 1 );
6859+ stringset = EnsureCapacity (isolate, stringset);
68606860 uint32_t hash = ShapeT::Hash (isolate, *name);
68616861 int entry = stringset->FindInsertionEntry (hash);
68626862 stringset->set (EntryToIndex (entry), *name);
@@ -6874,7 +6874,7 @@ Handle<ObjectHashSet> ObjectHashSet::Add(Isolate* isolate,
68746874 Handle<Object> key) {
68756875 int32_t hash = key->GetOrCreateHash (isolate).value ();
68766876 if (!set->Has (isolate, key, hash)) {
6877- set = EnsureCapacity (isolate, set, 1 );
6877+ set = EnsureCapacity (isolate, set);
68786878 int entry = set->FindInsertionEntry (hash);
68796879 set->set (EntryToIndex (entry), *key);
68806880 set->ElementAdded ();
@@ -7070,7 +7070,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutScript(
70707070 src = String::Flatten (isolate, src);
70717071 StringSharedKey key (src, shared, language_mode, kNoSourcePosition );
70727072 Handle<Object> k = key.AsHandle (isolate);
7073- cache = EnsureCapacity (isolate, cache, 1 );
7073+ cache = EnsureCapacity (isolate, cache);
70747074 int entry = cache->FindInsertionEntry (key.Hash ());
70757075 cache->set (EntryToIndex (entry), *k);
70767076 cache->set (EntryToIndex (entry) + 1 , *value);
@@ -7102,7 +7102,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
71027102 }
71037103 }
71047104
7105- cache = EnsureCapacity (isolate, cache, 1 );
7105+ cache = EnsureCapacity (isolate, cache);
71067106 int entry = cache->FindInsertionEntry (key.Hash ());
71077107 Handle<Object> k =
71087108 isolate->factory ()->NewNumber (static_cast <double >(key.Hash ()));
@@ -7116,7 +7116,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
71167116 Isolate* isolate, Handle<CompilationCacheTable> cache, Handle<String> src,
71177117 JSRegExp::Flags flags, Handle<FixedArray> value) {
71187118 RegExpKey key (src, flags);
7119- cache = EnsureCapacity (isolate, cache, 1 );
7119+ cache = EnsureCapacity (isolate, cache);
71207120 int entry = cache->FindInsertionEntry (key.Hash ());
71217121 // We store the value in the key slot, and compare the search key
71227122 // to the stored value with a custon IsMatch function during lookups.
@@ -7178,15 +7178,16 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::New(
71787178 Handle<Derived> dict = Dictionary<Derived, Shape>::New (
71797179 isolate, at_least_space_for, allocation, capacity_option);
71807180 dict->SetHash (PropertyArray::kNoHashSentinel );
7181- dict->SetNextEnumerationIndex (PropertyDetails::kInitialIndex );
7181+ dict->set_next_enumeration_index (PropertyDetails::kInitialIndex );
71827182 return dict;
71837183}
71847184
71857185template <typename Derived, typename Shape>
7186- Handle<Derived> BaseNameDictionary<Derived, Shape>::EnsureCapacity(
7187- Isolate* isolate, Handle<Derived> dictionary, int n) {
7188- // Check whether there are enough enumeration indices to add n elements.
7189- if (!PropertyDetails::IsValidIndex (dictionary->NextEnumerationIndex () + n)) {
7186+ int BaseNameDictionary<Derived, Shape>::NextEnumerationIndex(
7187+ Isolate* isolate, Handle<Derived> dictionary) {
7188+ int index = dictionary->next_enumeration_index ();
7189+ // Check whether the next enumeration index is valid.
7190+ if (!PropertyDetails::IsValidIndex (index)) {
71907191 // If not, we generate new indices for the properties.
71917192 int length = dictionary->NumberOfElements ();
71927193
@@ -7207,11 +7208,12 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::EnsureCapacity(
72077208 dictionary->DetailsAtPut (isolate, index, new_details);
72087209 }
72097210
7210- // Set the next enumeration index.
7211- dictionary->SetNextEnumerationIndex (PropertyDetails::kInitialIndex +
7212- length);
7211+ index = PropertyDetails::kInitialIndex + length;
72137212 }
7214- return HashTable<Derived, Shape>::EnsureCapacity (isolate, dictionary, n);
7213+
7214+ // Don't update the next enumeration index here, since we might be looking at
7215+ // an immutable empty dictionary.
7216+ return index;
72157217}
72167218
72177219template <typename Derived, typename Shape>
@@ -7260,13 +7262,13 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::Add(
72607262 DCHECK_EQ (0 , details.dictionary_index ());
72617263 // Assign an enumeration index to the property and update
72627264 // SetNextEnumerationIndex.
7263- int index = dictionary-> NextEnumerationIndex ();
7265+ int index = Derived:: NextEnumerationIndex (isolate, dictionary );
72647266 details = details.set_index (index);
72657267 dictionary = AddNoUpdateNextEnumerationIndex (isolate, dictionary, key, value,
72667268 details, entry_out);
72677269 // Update enumeration index here in order to avoid potential modification of
72687270 // the canonical empty dictionary which lives in read only space.
7269- dictionary->SetNextEnumerationIndex (index + 1 );
7271+ dictionary->set_next_enumeration_index (index + 1 );
72707272 return dictionary;
72717273}
72727274
@@ -7280,7 +7282,7 @@ Handle<Derived> Dictionary<Derived, Shape>::Add(Isolate* isolate,
72807282 // Valdate key is absent.
72817283 SLOW_DCHECK ((dictionary->FindEntry (isolate, key) == Dictionary::kNotFound ));
72827284 // Check whether the dictionary should be extended.
7283- dictionary = Derived::EnsureCapacity (isolate, dictionary, 1 );
7285+ dictionary = Derived::EnsureCapacity (isolate, dictionary);
72847286
72857287 // Compute the key object.
72867288 Handle<Object> k = Shape::AsHandle (isolate, key);
@@ -7625,7 +7627,7 @@ Handle<Derived> ObjectHashTableBase<Derived, Shape>::Put(Isolate* isolate,
76257627 }
76267628
76277629 // Check whether the hash table should be extended.
7628- table = Derived::EnsureCapacity (isolate, table, 1 );
7630+ table = Derived::EnsureCapacity (isolate, table);
76297631 table->AddEntry (table->FindInsertionEntry (hash), *key, *value);
76307632 return table;
76317633}
@@ -7873,8 +7875,8 @@ Handle<PropertyCell> PropertyCell::PrepareForValue(
78737875 // Preserve the enumeration index unless the property was deleted or never
78747876 // initialized.
78757877 if (cell->value ().IsTheHole (isolate)) {
7876- index = dictionary-> NextEnumerationIndex ();
7877- dictionary->SetNextEnumerationIndex (index + 1 );
7878+ index = GlobalDictionary:: NextEnumerationIndex (isolate, dictionary );
7879+ dictionary->set_next_enumeration_index (index + 1 );
78787880 } else {
78797881 index = original_details.dictionary_index ();
78807882 }
0 commit comments