Commit 78e23b2b authored by verwaest's avatar verwaest Committed by Commit bot

Avoid duplicate lookups when Get+Creating identity hashes

BUG=

Review URL: https://codereview.chromium.org/1765633004

Cr-Commit-Position: refs/heads/master@{#34500}
parent e8dd6981
......@@ -1049,15 +1049,24 @@ bool Object::HasSpecificClassOf(String* name) {
MaybeHandle<Object> Object::GetProperty(Handle<Object> object,
Handle<Name> name) {
LookupIterator it(object, name);
if (!it.IsFound()) return it.factory()->undefined_value();
return GetProperty(&it);
}
MaybeHandle<Object> Object::GetElement(Isolate* isolate, Handle<Object> object,
uint32_t index) {
LookupIterator it(isolate, object, index);
if (!it.IsFound()) return it.factory()->undefined_value();
return GetProperty(&it);
}
Handle<Object> JSReceiver::GetDataProperty(Handle<JSReceiver> object,
Handle<Name> name) {
LookupIterator it(object, name,
LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
if (!it.IsFound()) return it.factory()->undefined_value();
return GetDataProperty(&it);
}
MaybeHandle<Object> Object::SetElement(Isolate* isolate, Handle<Object> object,
uint32_t index, Handle<Object> value,
......
......@@ -836,14 +836,6 @@ MaybeHandle<Object> JSProxy::GetProperty(Isolate* isolate,
}
Handle<Object> JSReceiver::GetDataProperty(Handle<JSReceiver> object,
Handle<Name> name) {
LookupIterator it(object, name,
LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
return GetDataProperty(&it);
}
Handle<Object> JSReceiver::GetDataProperty(LookupIterator* it) {
for (; it->IsFound(); it->Next()) {
switch (it->state()) {
......@@ -5856,14 +5848,6 @@ static Smi* GenerateIdentityHash(Isolate* isolate) {
}
void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) {
DCHECK(!object->IsJSGlobalProxy());
Isolate* isolate = object->GetIsolate();
Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol();
JSObject::AddProperty(object, hash_code_symbol, hash, NONE);
}
template<typename ProxyType>
static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) {
Isolate* isolate = proxy->GetIsolate();
......@@ -5893,11 +5877,18 @@ Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) {
}
Isolate* isolate = object->GetIsolate();
Handle<Object> maybe_hash = JSObject::GetIdentityHash(isolate, object);
if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash);
Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol();
LookupIterator it(object, hash_code_symbol, LookupIterator::OWN);
if (it.IsFound()) {
DCHECK_EQ(LookupIterator::DATA, it.state());
Handle<Object> maybe_hash = it.GetDataValue();
if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash);
}
Handle<Smi> hash(GenerateIdentityHash(isolate), isolate);
SetIdentityHash(object, hash);
CHECK(AddDataProperty(&it, hash, NONE, THROW_ON_ERROR,
CERTAINLY_NOT_STORE_FROM_KEYED)
.IsJust());
return hash;
}
......
......@@ -1925,9 +1925,8 @@ class JSReceiver: public HeapObject {
bool from_javascript,
ShouldThrow should_throw);
static Handle<Object> GetDataProperty(Handle<JSReceiver> object,
Handle<Name> name);
inline static Handle<Object> GetDataProperty(Handle<JSReceiver> object,
Handle<Name> name);
static Handle<Object> GetDataProperty(LookupIterator* it);
......@@ -2213,8 +2212,6 @@ class JSObject: public JSReceiver {
// Returns true if the object has a property with the hidden string as name.
static bool HasHiddenProperties(Handle<JSObject> object);
static void SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash);
static void ValidateElements(Handle<JSObject> object);
// Makes sure that this object can contain HeapObject as elements.
......
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