Skip to content

Commit c1e972d

Browse files
committed
Fastpath for hasOwnProperty == true.
1 parent ade59a0 commit c1e972d

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

lib/Runtime/Base/ScriptContext.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,22 +1454,33 @@ if (!sourceList)
14541454
return NULL;
14551455
}
14561456

1457-
1458-
PropertyString* ScriptContext::GetPropertyString(PropertyId propertyId)
1457+
PropertyString* ScriptContext::TryGetPropertyString(PropertyId propertyId)
14591458
{
14601459
PropertyStringCacheMap* propertyStringMap = this->GetLibrary()->EnsurePropertyStringMap();
14611460

1462-
PropertyString *string;
14631461
RecyclerWeakReference<PropertyString>* stringReference;
14641462
if (propertyStringMap->TryGetValue(propertyId, &stringReference))
14651463
{
1466-
string = stringReference->Get();
1464+
PropertyString *string = stringReference->Get();
14671465
if (string != nullptr)
14681466
{
14691467
return string;
14701468
}
14711469
}
14721470

1471+
return nullptr;
1472+
}
1473+
1474+
PropertyString* ScriptContext::GetPropertyString(PropertyId propertyId)
1475+
{
1476+
PropertyString *string = TryGetPropertyString(propertyId);
1477+
if (string != nullptr)
1478+
{
1479+
return string;
1480+
}
1481+
1482+
PropertyStringCacheMap* propertyStringMap = this->GetLibrary()->EnsurePropertyStringMap();
1483+
14731484
const Js::PropertyRecord* propertyName = this->GetPropertyName(propertyId);
14741485
string = this->GetLibrary()->CreatePropertyString(propertyName);
14751486
propertyStringMap->Item(propertyId, recycler->CreateWeakReferenceHandle(string));

lib/Runtime/Base/ScriptContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ namespace Js
13371337
void SetDisposeDisposeByFaultInjectionEventHandler(EventHandler eventHandler);
13381338
#endif
13391339
EnumeratedObjectCache* GetEnumeratedObjectCache() { return &(cache->enumObjCache); }
1340+
PropertyString* TryGetPropertyString(PropertyId propertyId);
13401341
PropertyString* GetPropertyString(PropertyId propertyId);
13411342
void InvalidatePropertyStringCache(PropertyId propertyId, Type* type);
13421343
JavascriptString* GetIntegerString(Var aValue);

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,9 @@ namespace Js
10751075

10761076
BOOL JavascriptOperators::HasOwnProperty(Var instance, PropertyId propertyId, ScriptContext *requestContext)
10771077
{
1078-
BOOL result;
10791078
if (TaggedNumber::Is(instance))
10801079
{
1081-
result = false;
1080+
return FALSE;
10821081
}
10831082
else
10841083
{
@@ -1091,10 +1090,22 @@ namespace Js
10911090
}
10921091
else
10931092
{
1093+
PropertyString *propString = requestContext->TryGetPropertyString(propertyId);
1094+
if (propString != nullptr)
1095+
{
1096+
const PropertyCache *propCache = propString->GetPropertyCache();
1097+
if (object->GetType() == propCache->type)
1098+
{
1099+
// The type cached for the property was the same as the type of this object
1100+
// (i.e. obj in obj.hasOwnProperty), so we know the answer is "true".
1101+
Assert(TRUE == (object && object->HasOwnProperty(propertyId))); // sanity check on the fastpath result
1102+
return TRUE;
1103+
}
1104+
}
1105+
10941106
return object && object->HasOwnProperty(propertyId);
10951107
}
10961108
}
1097-
return result;
10981109
}
10991110

11001111
BOOL JavascriptOperators::GetOwnAccessors(Var instance, PropertyId propertyId, Var* getter, Var* setter, ScriptContext * requestContext)

0 commit comments

Comments
 (0)