@@ -6663,7 +6663,7 @@ void StringTable::EnsureCapacityForDeserialization(Isolate* isolate,
6663
6663
int expected) {
6664
6664
Handle<StringTable> table = isolate->factory()->string_table();
6665
6665
// We need a key instance for the virtual hash function.
6666
- table = StringTable:: EnsureCapacity(isolate, table, expected);
6666
+ table = EnsureCapacity(isolate, table, expected);
6667
6667
isolate->heap()->SetRootStringTable(*table);
6668
6668
}
6669
6669
@@ -6715,7 +6715,7 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, StringTableKey* key) {
6715
6715
6716
6716
table = StringTable::CautiousShrink(isolate, table);
6717
6717
// Adding new string. Grow table if needed.
6718
- table = StringTable:: EnsureCapacity(isolate, table, 1 );
6718
+ table = EnsureCapacity(isolate, table);
6719
6719
isolate->heap()->SetRootStringTable(*table);
6720
6720
6721
6721
return AddKeyNoResize(isolate, key);
@@ -6856,7 +6856,7 @@ Handle<StringSet> StringSet::New(Isolate* isolate) {
6856
6856
Handle<StringSet> StringSet::Add(Isolate* isolate, Handle<StringSet> stringset,
6857
6857
Handle<String> name) {
6858
6858
if (!stringset->Has(isolate, name)) {
6859
- stringset = EnsureCapacity(isolate, stringset, 1 );
6859
+ stringset = EnsureCapacity(isolate, stringset);
6860
6860
uint32_t hash = ShapeT::Hash(isolate, *name);
6861
6861
int entry = stringset->FindInsertionEntry(hash);
6862
6862
stringset->set(EntryToIndex(entry), *name);
@@ -6874,7 +6874,7 @@ Handle<ObjectHashSet> ObjectHashSet::Add(Isolate* isolate,
6874
6874
Handle<Object> key) {
6875
6875
int32_t hash = key->GetOrCreateHash(isolate).value();
6876
6876
if (!set->Has(isolate, key, hash)) {
6877
- set = EnsureCapacity(isolate, set, 1 );
6877
+ set = EnsureCapacity(isolate, set);
6878
6878
int entry = set->FindInsertionEntry(hash);
6879
6879
set->set(EntryToIndex(entry), *key);
6880
6880
set->ElementAdded();
@@ -7070,7 +7070,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutScript(
7070
7070
src = String::Flatten(isolate, src);
7071
7071
StringSharedKey key(src, shared, language_mode, kNoSourcePosition);
7072
7072
Handle<Object> k = key.AsHandle(isolate);
7073
- cache = EnsureCapacity(isolate, cache, 1 );
7073
+ cache = EnsureCapacity(isolate, cache);
7074
7074
int entry = cache->FindInsertionEntry(key.Hash());
7075
7075
cache->set(EntryToIndex(entry), *k);
7076
7076
cache->set(EntryToIndex(entry) + 1, *value);
@@ -7102,7 +7102,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
7102
7102
}
7103
7103
}
7104
7104
7105
- cache = EnsureCapacity(isolate, cache, 1 );
7105
+ cache = EnsureCapacity(isolate, cache);
7106
7106
int entry = cache->FindInsertionEntry(key.Hash());
7107
7107
Handle<Object> k =
7108
7108
isolate->factory()->NewNumber(static_cast<double>(key.Hash()));
@@ -7116,7 +7116,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
7116
7116
Isolate* isolate, Handle<CompilationCacheTable> cache, Handle<String> src,
7117
7117
JSRegExp::Flags flags, Handle<FixedArray> value) {
7118
7118
RegExpKey key(src, flags);
7119
- cache = EnsureCapacity(isolate, cache, 1 );
7119
+ cache = EnsureCapacity(isolate, cache);
7120
7120
int entry = cache->FindInsertionEntry(key.Hash());
7121
7121
// We store the value in the key slot, and compare the search key
7122
7122
// to the stored value with a custon IsMatch function during lookups.
@@ -7178,15 +7178,16 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::New(
7178
7178
Handle<Derived> dict = Dictionary<Derived, Shape>::New(
7179
7179
isolate, at_least_space_for, allocation, capacity_option);
7180
7180
dict->SetHash(PropertyArray::kNoHashSentinel);
7181
- dict->SetNextEnumerationIndex (PropertyDetails::kInitialIndex);
7181
+ dict->set_next_enumeration_index (PropertyDetails::kInitialIndex);
7182
7182
return dict;
7183
7183
}
7184
7184
7185
7185
template <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)) {
7190
7191
// If not, we generate new indices for the properties.
7191
7192
int length = dictionary->NumberOfElements();
7192
7193
@@ -7207,11 +7208,12 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::EnsureCapacity(
7207
7208
dictionary->DetailsAtPut(isolate, index, new_details);
7208
7209
}
7209
7210
7210
- // Set the next enumeration index.
7211
- dictionary->SetNextEnumerationIndex(PropertyDetails::kInitialIndex +
7212
- length);
7211
+ index = PropertyDetails::kInitialIndex + length;
7213
7212
}
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;
7215
7217
}
7216
7218
7217
7219
template <typename Derived, typename Shape>
@@ -7260,13 +7262,13 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::Add(
7260
7262
DCHECK_EQ(0, details.dictionary_index());
7261
7263
// Assign an enumeration index to the property and update
7262
7264
// SetNextEnumerationIndex.
7263
- int index = dictionary-> NextEnumerationIndex();
7265
+ int index = Derived:: NextEnumerationIndex(isolate, dictionary );
7264
7266
details = details.set_index(index);
7265
7267
dictionary = AddNoUpdateNextEnumerationIndex(isolate, dictionary, key, value,
7266
7268
details, entry_out);
7267
7269
// Update enumeration index here in order to avoid potential modification of
7268
7270
// the canonical empty dictionary which lives in read only space.
7269
- dictionary->SetNextEnumerationIndex (index + 1);
7271
+ dictionary->set_next_enumeration_index (index + 1);
7270
7272
return dictionary;
7271
7273
}
7272
7274
@@ -7280,7 +7282,7 @@ Handle<Derived> Dictionary<Derived, Shape>::Add(Isolate* isolate,
7280
7282
// Valdate key is absent.
7281
7283
SLOW_DCHECK((dictionary->FindEntry(isolate, key) == Dictionary::kNotFound));
7282
7284
// Check whether the dictionary should be extended.
7283
- dictionary = Derived::EnsureCapacity(isolate, dictionary, 1 );
7285
+ dictionary = Derived::EnsureCapacity(isolate, dictionary);
7284
7286
7285
7287
// Compute the key object.
7286
7288
Handle<Object> k = Shape::AsHandle(isolate, key);
@@ -7625,7 +7627,7 @@ Handle<Derived> ObjectHashTableBase<Derived, Shape>::Put(Isolate* isolate,
7625
7627
}
7626
7628
7627
7629
// Check whether the hash table should be extended.
7628
- table = Derived::EnsureCapacity(isolate, table, 1 );
7630
+ table = Derived::EnsureCapacity(isolate, table);
7629
7631
table->AddEntry(table->FindInsertionEntry(hash), *key, *value);
7630
7632
return table;
7631
7633
}
@@ -7873,8 +7875,8 @@ Handle<PropertyCell> PropertyCell::PrepareForValue(
7873
7875
// Preserve the enumeration index unless the property was deleted or never
7874
7876
// initialized.
7875
7877
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);
7878
7880
} else {
7879
7881
index = original_details.dictionary_index();
7880
7882
}
0 commit comments