Commit e5e05015 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[dict] Remove HasKey from OrderedNameDictionary

Since we have FindEntry, this is redudant.

This patch also
* Makes the tests for FindEntry stricter by testing the value
* Makes the OrderedNameDictionary::Add and
  SmallOrderedNameDictionary::Add consistent by using GetHash and
  using a DCHECK for the FindEntry call

Bug: v8:6443, v8:7569
Change-Id: I4859cd6735ec385c19acad6ce5cecaeac45173dd
Reviewed-on: https://chromium-review.googlesource.com/c/1382828
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58380}
parent 4ba29d05
......@@ -82,9 +82,8 @@ Handle<Derived> OrderedHashTable<Derived, entrysize>::Clear(
template <class Derived, int entrysize>
bool OrderedHashTable<Derived, entrysize>::HasKey(Isolate* isolate,
Derived table, Object* key) {
DCHECK((entrysize == 1 && table->IsOrderedHashSet()) ||
(entrysize == 2 && table->IsOrderedHashMap()) ||
(entrysize == 3 && table->IsOrderedNameDictionary()));
DCHECK_IMPLIES(entrysize == 1, table->IsOrderedHashSet());
DCHECK_IMPLIES(entrysize == 2, table->IsOrderedHashMap());
DisallowHeapAllocation no_gc;
int entry = table->FindEntry(isolate, key);
return entry != kNotFound;
......@@ -316,30 +315,38 @@ Handle<OrderedHashMap> OrderedHashMap::Add(Isolate* isolate,
return table;
}
Handle<OrderedNameDictionary> OrderedNameDictionary::Add(
Isolate* isolate, Handle<OrderedNameDictionary> table, Handle<Name> key,
Handle<Object> value, PropertyDetails details) {
int hash = key->Hash();
template <>
int OrderedHashTable<OrderedNameDictionary, 3>::FindEntry(Isolate* isolate,
Object* key) {
DisallowHeapAllocation no_gc;
#ifdef DEBUG
// Walk the chain of the bucket and try finding the key.
{
DisallowHeapAllocation no_gc;
int entry = table->HashToEntry(hash);
Object* raw_key = *key;
while (entry != kNotFound) {
Object* candidate_key = table->KeyAt(entry);
DCHECK(key->IsUniqueName());
Name raw_key = Name::cast(key);
// Key should not exist already!
CHECK(!candidate_key->SameValueZero(raw_key));
int entry = HashToEntry(raw_key->Hash());
while (entry != kNotFound) {
Object* candidate_key = KeyAt(entry);
DCHECK(candidate_key->IsTheHole() ||
Name::cast(candidate_key)->IsUniqueName());
if (candidate_key == raw_key) return entry;
entry = table->NextChainEntry(entry);
}
// TODO(gsathya): This is loading the bucket count from the hash
// table for every iteration. This should be peeled out of the
// loop.
entry = NextChainEntry(entry);
}
#endif
return kNotFound;
}
Handle<OrderedNameDictionary> OrderedNameDictionary::Add(
Isolate* isolate, Handle<OrderedNameDictionary> table, Handle<Name> key,
Handle<Object> value, PropertyDetails details) {
DCHECK_EQ(kNotFound, table->FindEntry(isolate, *key));
table = OrderedNameDictionary::EnsureGrowable(isolate, table);
// Read the existing bucket values.
int hash = key->Hash();
int bucket = table->HashToBucket(hash);
int previous_entry = table->HashToEntry(hash);
int nof = table->NumberOfElements();
......@@ -361,29 +368,6 @@ Handle<OrderedNameDictionary> OrderedNameDictionary::Add(
return table;
}
template <>
int OrderedHashTable<OrderedNameDictionary, 3>::FindEntry(Isolate* isolate,
Object* key) {
DisallowHeapAllocation no_gc;
DCHECK(key->IsUniqueName());
Name raw_key = Name::cast(key);
int entry = HashToEntry(raw_key->Hash());
while (entry != kNotFound) {
Object* candidate_key = KeyAt(entry);
DCHECK(candidate_key->IsTheHole() ||
Name::cast(candidate_key)->IsUniqueName());
if (candidate_key == raw_key) return entry;
// TODO(gsathya): This is loading the bucket count from the hash
// table for every iteration. This should be peeled out of the
// loop.
entry = NextChainEntry(entry);
}
return kNotFound;
}
Handle<OrderedHashSet> OrderedHashSet::Allocate(Isolate* isolate, int capacity,
PretenureFlag pretenure) {
return OrderedHashTable<OrderedHashSet, 1>::Allocate(isolate, capacity,
......@@ -448,9 +432,6 @@ template int OrderedHashTable<OrderedHashMap, 2>::FindEntry(Isolate* isolate,
Object* key);
template bool OrderedHashTable<OrderedNameDictionary, 3>::HasKey(
Isolate* isolate, OrderedNameDictionary table, Object* key);
template Handle<OrderedNameDictionary>
OrderedHashTable<OrderedNameDictionary, 3>::EnsureGrowable(
Isolate* isolate, Handle<OrderedNameDictionary> table);
......@@ -588,10 +569,29 @@ MaybeHandle<SmallOrderedHashMap> SmallOrderedHashMap::Add(
return table;
}
template <>
int SmallOrderedHashTable<SmallOrderedNameDictionary>::FindEntry(
Isolate* isolate, Object* key) {
DisallowHeapAllocation no_gc;
DCHECK(key->IsUniqueName());
Name raw_key = Name::cast(key);
int entry = HashToFirstEntry(raw_key->Hash());
// Walk the chain in the bucket to find the key.
while (entry != kNotFound) {
Object* candidate_key = KeyAt(entry);
if (candidate_key == key) return entry;
entry = GetNextEntry(entry);
}
return kNotFound;
}
MaybeHandle<SmallOrderedNameDictionary> SmallOrderedNameDictionary::Add(
Isolate* isolate, Handle<SmallOrderedNameDictionary> table,
Handle<Name> key, Handle<Object> value, PropertyDetails details) {
DCHECK(!table->HasKey(isolate, key));
DCHECK_EQ(kNotFound, table->FindEntry(isolate, *key));
if (table->UsedCapacity() >= table->Capacity()) {
MaybeHandle<SmallOrderedNameDictionary> new_table =
......@@ -601,10 +601,10 @@ MaybeHandle<SmallOrderedNameDictionary> SmallOrderedNameDictionary::Add(
}
}
int hash = key->GetOrCreateHash(isolate)->value();
int nof = table->NumberOfElements();
// Read the existing bucket values.
int hash = key->Hash();
int bucket = table->HashToBucket(hash);
int previous_entry = table->HashToFirstEntry(hash);
......@@ -761,25 +761,6 @@ int SmallOrderedHashTable<Derived>::FindEntry(Isolate* isolate, Object* key) {
return kNotFound;
}
template <>
int SmallOrderedHashTable<SmallOrderedNameDictionary>::FindEntry(
Isolate* isolate, Object* key) {
DisallowHeapAllocation no_gc;
DCHECK(key->IsUniqueName());
Name raw_key = Name::cast(key);
int entry = HashToFirstEntry(raw_key->Hash());
// Walk the chain in the bucket to find the key.
while (entry != kNotFound) {
Object* candidate_key = KeyAt(entry);
if (candidate_key == key) return entry;
entry = GetNextEntry(entry);
}
return kNotFound;
}
template bool SmallOrderedHashTable<SmallOrderedHashSet>::HasKey(
Isolate* isolate, Handle<Object> key);
template Handle<SmallOrderedHashSet>
......@@ -809,8 +790,6 @@ template bool SmallOrderedHashTable<SmallOrderedHashSet>::Delete(
template void SmallOrderedHashTable<SmallOrderedNameDictionary>::Initialize(
Isolate* isolate, int capacity);
template bool SmallOrderedHashTable<SmallOrderedNameDictionary>::HasKey(
Isolate* isolate, Handle<Object> key);
template <class SmallTable, class LargeTable>
Handle<HeapObject> OrderedHashTableHandler<SmallTable, LargeTable>::Allocate(
......
This diff is collapsed.
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