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

Revert "[OrderedHashSet] Remove redundant hash to bucket"

This reverts commit 88376a78.

Reason for revert: the number of buckets could change, so we can't cache the value

Original change's description:
> [OrderedHashSet] Remove redundant hash to bucket
> 
> Bug: v8:5717
> Change-Id: I88e1e3089844b0955f0f7a6a792c2e10949a5b18
> Reviewed-on: https://chromium-review.googlesource.com/480927
> Reviewed-by: Adam Klein <adamk@chromium.org>
> Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#44707}

TBR=adamk@chromium.org,cbruni@chromium.org,gsathya@chromium.org,v8-reviews@googlegroups.com
# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I4d42021a1d1f5bc069b3787efc828761098038e0
Reviewed-on: https://chromium-review.googlesource.com/483903Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44760}
parent 5204f087
...@@ -18868,8 +18868,7 @@ bool OrderedHashTable<Derived, entrysize>::HasKey(Handle<Derived> table, ...@@ -18868,8 +18868,7 @@ bool OrderedHashTable<Derived, entrysize>::HasKey(Handle<Derived> table,
Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table, Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table,
Handle<Object> key) { Handle<Object> key) {
int hash = Object::GetOrCreateHash(table->GetIsolate(), key)->value(); int hash = Object::GetOrCreateHash(table->GetIsolate(), key)->value();
int bucket = table->HashToBucket(hash); int previous_entry = table->HashToEntry(hash);
int previous_entry = table->HashToEntry(hash, bucket);
int entry = previous_entry; int entry = previous_entry;
// Walk the chain of the bucket and try finding the key. // Walk the chain of the bucket and try finding the key.
while (entry != kNotFound) { while (entry != kNotFound) {
...@@ -18881,6 +18880,7 @@ Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table, ...@@ -18881,6 +18880,7 @@ Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table,
table = OrderedHashSet::EnsureGrowable(table); table = OrderedHashSet::EnsureGrowable(table);
// Read the existing bucket values. // Read the existing bucket values.
int bucket = table->HashToBucket(hash);
int nof = table->NumberOfElements(); int nof = table->NumberOfElements();
// Insert a new entry at the end, // Insert a new entry at the end,
int new_entry = nof + table->NumberOfDeletedElements(); int new_entry = nof + table->NumberOfDeletedElements();
......
...@@ -410,18 +410,17 @@ class OrderedHashTable : public FixedArray { ...@@ -410,18 +410,17 @@ class OrderedHashTable : public FixedArray {
int HashToBucket(int hash) { return hash & (NumberOfBuckets() - 1); } int HashToBucket(int hash) { return hash & (NumberOfBuckets() - 1); }
int HashToEntry(int hash, int bucket) { int HashToEntry(int hash) {
int bucket = HashToBucket(hash);
Object* entry = this->get(kHashTableStartIndex + bucket); Object* entry = this->get(kHashTableStartIndex + bucket);
return Smi::cast(entry)->value(); return Smi::cast(entry)->value();
} }
int KeyToFirstEntry(Isolate* isolate, Object* key) { int KeyToFirstEntry(Isolate* isolate, Object* key) {
Object* hash_obj = key->GetHash(); Object* hash = key->GetHash();
// If the object does not have an identity hash, it was never used as a key // If the object does not have an identity hash, it was never used as a key
if (hash_obj->IsUndefined(isolate)) return kNotFound; if (hash->IsUndefined(isolate)) return kNotFound;
int hash = Smi::cast(hash_obj)->value(); return HashToEntry(Smi::cast(hash)->value());
int bucket = HashToBucket(hash);
return HashToEntry(hash, bucket);
} }
int NextChainEntry(int entry) { int NextChainEntry(int entry) {
......
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