@@ -6677,7 +6677,7 @@ void StringTable::EnsureCapacityForDeserialization(Isolate* isolate,
6677
6677
int expected) {
6678
6678
Handle<StringTable> table = isolate->factory ()->string_table ();
6679
6679
// We need a key instance for the virtual hash function.
6680
- table = StringTable:: EnsureCapacity (isolate, table, expected);
6680
+ table = EnsureCapacity (isolate, table, expected);
6681
6681
isolate->heap ()->SetRootStringTable (*table);
6682
6682
}
6683
6683
@@ -6729,7 +6729,7 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, StringTableKey* key) {
6729
6729
6730
6730
table = StringTable::CautiousShrink (isolate, table);
6731
6731
// Adding new string. Grow table if needed.
6732
- table = StringTable:: EnsureCapacity (isolate, table, 1 );
6732
+ table = EnsureCapacity (isolate, table);
6733
6733
isolate->heap ()->SetRootStringTable (*table);
6734
6734
6735
6735
return AddKeyNoResize (isolate, key);
@@ -6870,7 +6870,7 @@ Handle<StringSet> StringSet::New(Isolate* isolate) {
6870
6870
Handle<StringSet> StringSet::Add (Isolate* isolate, Handle<StringSet> stringset,
6871
6871
Handle<String> name) {
6872
6872
if (!stringset->Has (isolate, name)) {
6873
- stringset = EnsureCapacity (isolate, stringset, 1 );
6873
+ stringset = EnsureCapacity (isolate, stringset);
6874
6874
uint32_t hash = ShapeT::Hash (isolate, *name);
6875
6875
int entry = stringset->FindInsertionEntry (hash);
6876
6876
stringset->set (EntryToIndex (entry), *name);
@@ -6888,7 +6888,7 @@ Handle<ObjectHashSet> ObjectHashSet::Add(Isolate* isolate,
6888
6888
Handle<Object> key) {
6889
6889
int32_t hash = key->GetOrCreateHash (isolate).value ();
6890
6890
if (!set->Has (isolate, key, hash)) {
6891
- set = EnsureCapacity (isolate, set, 1 );
6891
+ set = EnsureCapacity (isolate, set);
6892
6892
int entry = set->FindInsertionEntry (hash);
6893
6893
set->set (EntryToIndex (entry), *key);
6894
6894
set->ElementAdded ();
@@ -7084,7 +7084,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutScript(
7084
7084
src = String::Flatten (isolate, src);
7085
7085
StringSharedKey key (src, shared, language_mode, kNoSourcePosition );
7086
7086
Handle<Object> k = key.AsHandle (isolate);
7087
- cache = EnsureCapacity (isolate, cache, 1 );
7087
+ cache = EnsureCapacity (isolate, cache);
7088
7088
int entry = cache->FindInsertionEntry (key.Hash ());
7089
7089
cache->set (EntryToIndex (entry), *k);
7090
7090
cache->set (EntryToIndex (entry) + 1 , *value);
@@ -7116,7 +7116,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
7116
7116
}
7117
7117
}
7118
7118
7119
- cache = EnsureCapacity (isolate, cache, 1 );
7119
+ cache = EnsureCapacity (isolate, cache);
7120
7120
int entry = cache->FindInsertionEntry (key.Hash ());
7121
7121
Handle<Object> k =
7122
7122
isolate->factory ()->NewNumber (static_cast <double >(key.Hash ()));
@@ -7130,7 +7130,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
7130
7130
Isolate* isolate, Handle<CompilationCacheTable> cache, Handle<String> src,
7131
7131
JSRegExp::Flags flags, Handle<FixedArray> value) {
7132
7132
RegExpKey key (src, flags);
7133
- cache = EnsureCapacity (isolate, cache, 1 );
7133
+ cache = EnsureCapacity (isolate, cache);
7134
7134
int entry = cache->FindInsertionEntry (key.Hash ());
7135
7135
// We store the value in the key slot, and compare the search key
7136
7136
// to the stored value with a custon IsMatch function during lookups.
@@ -7192,15 +7192,16 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::New(
7192
7192
Handle<Derived> dict = Dictionary<Derived, Shape>::New (
7193
7193
isolate, at_least_space_for, allocation, capacity_option);
7194
7194
dict->SetHash (PropertyArray::kNoHashSentinel );
7195
- dict->SetNextEnumerationIndex (PropertyDetails::kInitialIndex );
7195
+ dict->set_next_enumeration_index (PropertyDetails::kInitialIndex );
7196
7196
return dict;
7197
7197
}
7198
7198
7199
7199
template <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)) {
7204
7205
// If not, we generate new indices for the properties.
7205
7206
int length = dictionary->NumberOfElements ();
7206
7207
@@ -7221,11 +7222,12 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::EnsureCapacity(
7221
7222
dictionary->DetailsAtPut (isolate, index, new_details);
7222
7223
}
7223
7224
7224
- // Set the next enumeration index.
7225
- dictionary->SetNextEnumerationIndex (PropertyDetails::kInitialIndex +
7226
- length);
7225
+ index = PropertyDetails::kInitialIndex + length;
7227
7226
}
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;
7229
7231
}
7230
7232
7231
7233
template <typename Derived, typename Shape>
@@ -7274,13 +7276,13 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::Add(
7274
7276
DCHECK_EQ (0 , details.dictionary_index ());
7275
7277
// Assign an enumeration index to the property and update
7276
7278
// SetNextEnumerationIndex.
7277
- int index = dictionary-> NextEnumerationIndex ();
7279
+ int index = Derived:: NextEnumerationIndex (isolate, dictionary );
7278
7280
details = details.set_index (index);
7279
7281
dictionary = AddNoUpdateNextEnumerationIndex (isolate, dictionary, key, value,
7280
7282
details, entry_out);
7281
7283
// Update enumeration index here in order to avoid potential modification of
7282
7284
// the canonical empty dictionary which lives in read only space.
7283
- dictionary->SetNextEnumerationIndex (index + 1 );
7285
+ dictionary->set_next_enumeration_index (index + 1 );
7284
7286
return dictionary;
7285
7287
}
7286
7288
@@ -7294,7 +7296,7 @@ Handle<Derived> Dictionary<Derived, Shape>::Add(Isolate* isolate,
7294
7296
// Valdate key is absent.
7295
7297
SLOW_DCHECK ((dictionary->FindEntry (isolate, key) == Dictionary::kNotFound ));
7296
7298
// Check whether the dictionary should be extended.
7297
- dictionary = Derived::EnsureCapacity (isolate, dictionary, 1 );
7299
+ dictionary = Derived::EnsureCapacity (isolate, dictionary);
7298
7300
7299
7301
// Compute the key object.
7300
7302
Handle<Object> k = Shape::AsHandle (isolate, key);
@@ -7644,7 +7646,7 @@ Handle<Derived> ObjectHashTableBase<Derived, Shape>::Put(Isolate* isolate,
7644
7646
}
7645
7647
7646
7648
// Check whether the hash table should be extended.
7647
- table = Derived::EnsureCapacity (isolate, table, 1 );
7649
+ table = Derived::EnsureCapacity (isolate, table);
7648
7650
table->AddEntry (table->FindInsertionEntry (hash), *key, *value);
7649
7651
return table;
7650
7652
}
@@ -7892,8 +7894,8 @@ Handle<PropertyCell> PropertyCell::PrepareForValue(
7892
7894
// Preserve the enumeration index unless the property was deleted or never
7893
7895
// initialized.
7894
7896
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 );
7897
7899
} else {
7898
7900
index = original_details.dictionary_index ();
7899
7901
}
0 commit comments