Commit f4ce0839 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[runtime] Templatize NameToIndexHashTable::Add with IsolateT

This hashtable will be used by ScopeInfo::Create which
is instantiated with Isolate and LocalIsolate.

Bug: v8:12315
Change-Id: I098c103eb884795ee84d50c0756af686c27ced31
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3398116
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78670}
parent 134220f5
......@@ -169,6 +169,13 @@ InternalIndex HashTable<Derived, Shape>::FindEntry(PtrComprCageBase cage_base,
}
}
template <typename Derived, typename Shape>
template <typename IsolateT>
InternalIndex HashTable<Derived, Shape>::FindInsertionEntry(IsolateT* isolate,
uint32_t hash) {
return FindInsertionEntry(isolate, ReadOnlyRoots(isolate), hash);
}
// static
template <typename Derived, typename Shape>
bool HashTable<Derived, Shape>::IsKey(ReadOnlyRoots roots, Object k) {
......@@ -279,6 +286,24 @@ uint32_t ObjectHashTableShape::HashForObject(ReadOnlyRoots roots,
return Smi::ToInt(other.GetHash());
}
template <typename IsolateT>
Handle<NameToIndexHashTable> NameToIndexHashTable::Add(
IsolateT* isolate, Handle<NameToIndexHashTable> table, Handle<Name> key,
int32_t index) {
DCHECK_GE(index, 0);
// Validate that the key is absent.
SLOW_DCHECK(table->FindEntry(isolate, key).is_not_found());
// Check whether the dictionary should be extended.
table = EnsureCapacity(isolate, table);
// Compute the key object.
InternalIndex entry = table->FindInsertionEntry(isolate, key->hash());
table->set(EntryToIndex(entry), *key);
table->set(EntryToValueIndex(entry), Smi::FromInt(index));
table->ElementAdded();
return table;
}
} // namespace internal
} // namespace v8
......
......@@ -227,7 +227,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
// has the given hash value.
InternalIndex FindInsertionEntry(PtrComprCageBase cage_base,
ReadOnlyRoots roots, uint32_t hash);
InternalIndex FindInsertionEntry(Isolate* isolate, uint32_t hash);
template <typename IsolateT>
InternalIndex FindInsertionEntry(IsolateT* isolate, uint32_t hash);
// Computes the capacity a table with the given capacity would need to have
// room for the given number of elements, also allowing it to shrink.
......@@ -457,9 +458,10 @@ class V8_EXPORT_PRIVATE NameToIndexHashTable
// Returns the value at entry.
Object ValueAt(InternalIndex entry);
V8_WARN_UNUSED_RESULT static Handle<NameToIndexHashTable> Add(
Isolate* isolate, Handle<NameToIndexHashTable> table, Handle<Name> key,
int32_t value);
template <typename IsolateT>
static Handle<NameToIndexHashTable> Add(IsolateT* isolate,
Handle<NameToIndexHashTable> table,
Handle<Name> key, int32_t value);
DECL_CAST(NameToIndexHashTable)
DECL_PRINTER(NameToIndexHashTable)
......
......@@ -5886,12 +5886,6 @@ InternalIndex HashTable<Derived, Shape>::FindInsertionEntry(
}
}
template <typename Derived, typename Shape>
InternalIndex HashTable<Derived, Shape>::FindInsertionEntry(Isolate* isolate,
uint32_t hash) {
return FindInsertionEntry(isolate, ReadOnlyRoots(isolate), hash);
}
base::Optional<PropertyCell>
GlobalDictionary::TryFindPropertyCellForConcurrentLookupIterator(
Isolate* isolate, Handle<Name> name, RelaxedLoadTag tag) {
......@@ -6242,23 +6236,6 @@ int32_t NameToIndexHashTable::Lookup(Handle<Name> key) {
return Smi::cast(this->get(EntryToValueIndex(entry))).value();
}
Handle<NameToIndexHashTable> NameToIndexHashTable::Add(
Isolate* isolate, Handle<NameToIndexHashTable> table, Handle<Name> key,
int32_t index) {
DCHECK_GE(index, 0);
// Validate that the key is absent.
SLOW_DCHECK(table->FindEntry(isolate, key).is_not_found());
// Check whether the dictionary should be extended.
table = EnsureCapacity(isolate, table);
// Compute the key object.
InternalIndex entry = table->FindInsertionEntry(isolate, key->hash());
table->set(EntryToIndex(entry), *key);
table->set(EntryToValueIndex(entry), Smi::FromInt(index));
table->ElementAdded();
return table;
}
template <typename Derived, typename Shape>
Object ObjectHashTableBase<Derived, Shape>::Lookup(Handle<Object> key) {
DisallowGarbageCollection no_gc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment