!9009 解释器hasownproperty性能优化

Merge pull request !9009 from jiangmengyang/hasownproperty
This commit is contained in:
openharmony_ci 2024-09-04 08:32:45 +00:00 committed by Gitee
commit 9dab80bc7c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 25 additions and 22 deletions

View File

@ -662,11 +662,12 @@ void BuiltinsObjectStubBuilder::HasOwnProperty(Variable *result, Label *exit, La
BRANCH(TaggedIsString(prop), &keyIsString, slowPath); // 2 : two args
Bind(&keyIsString);
{
GateRef res = CallRuntime(glue_, RTSTUB_ID(TryToElementsIndexOrFindInStringTable), { prop });
BRANCH(TaggedIsNumber(res), &isIndex, &notIndex);
GateRef res = StringToElementIndex(glue_, prop);
// -1: not find element index
BRANCH(Int64NotEqual(res, Int64(-1)), &isIndex, &notIndex);
Bind(&isIndex);
{
GateRef index = NumberGetInt(glue_, res);
GateRef index = TruncInt64ToInt32(res);
Label findByIndex(env);
GateRef elements = GetElementsArray(thisValue);
GateRef len = GetLengthOfTaggedArray(elements);
@ -709,7 +710,15 @@ void BuiltinsObjectStubBuilder::HasOwnProperty(Variable *result, Label *exit, La
Bind(&notIndex);
{
Label findInStringTabel(env);
BRANCH(TaggedIsHole(res), exit, &findInStringTabel);
Label notInternString(env);
DEFVARIABLE(stringTable, VariableType::JS_ANY(), prop);
BRANCH(IsInternalString(prop), &findInStringTabel, &notInternString);
Bind(&notInternString);
{
GateRef internString = CallRuntime(glue_, RTSTUB_ID(TryGetInternString), { prop });
stringTable = internString;
BRANCH(TaggedIsHole(internString), exit, &findInStringTabel)
}
Bind(&findInStringTabel);
{
Label isDicMode(env);
@ -721,7 +730,7 @@ void BuiltinsObjectStubBuilder::HasOwnProperty(Variable *result, Label *exit, La
GateRef layOutInfo = GetLayoutFromHClass(hclass);
GateRef propsNum = GetNumberOfPropsFromHClass(hclass);
// int entry = layoutInfo->FindElementWithCache(thread, hclass, key, propsNumber)
GateRef entryA = FindElementWithCache(glue_, layOutInfo, hclass, res, propsNum, hir);
GateRef entryA = FindElementWithCache(glue_, layOutInfo, hclass, *stringTable, propsNum, hir);
Label hasEntry(env);
// if branch condition : entry != -1
BRANCH(Int32NotEqual(entryA, Int32(-1)), &hasEntry, exit);
@ -735,7 +744,7 @@ void BuiltinsObjectStubBuilder::HasOwnProperty(Variable *result, Label *exit, La
{
GateRef array = GetPropertiesArray(thisValue);
// int entry = dict->FindEntry(key)
GateRef entryB = FindEntryFromNameDictionary(glue_, array, res, hir);
GateRef entryB = FindEntryFromNameDictionary(glue_, array, *stringTable, hir);
Label notNegtiveOne(env);
// if branch condition : entry != -1
BRANCH(Int32NotEqual(entryB, Int32(-1)), &notNegtiveOne, exit);

View File

@ -463,7 +463,6 @@ namespace panda::ecmascript {
V(HasProperty) \
V(DumpObject) \
V(TryGetInternString) \
V(TryToElementsIndexOrFindInStringTable) \
V(BigIntConstructor) \
V(ObjectPrototypeHasOwnProperty) \
V(ReflectHas) \

View File

@ -3007,20 +3007,6 @@ DEF_RUNTIME_STUBS(SlowFlattenString)
return JSTaggedValue(EcmaStringAccessor::SlowFlatten(thread->GetEcmaVM(), str)).GetRawData();
}
DEF_RUNTIME_STUBS(TryToElementsIndexOrFindInStringTable)
{
RUNTIME_STUBS_HEADER(TryToElementsIndexOrFindInStringTable);
JSHandle<EcmaString> string = GetHArg<EcmaString>(argv, argc, 0); // 0: means the zeroth parameter
uint32_t index = 0;
if (EcmaStringAccessor(string).ToElementIndex(&index)) {
return JSTaggedValue(index).GetRawData();
}
if (!EcmaStringAccessor(string).IsInternString()) {
return RuntimeTryGetInternString(argGlue, string);
}
return string.GetTaggedValue().GetRawData();
}
DEF_RUNTIME_STUBS(TryGetInternString)
{
RUNTIME_STUBS_HEADER(TryGetInternString);

View File

@ -30,3 +30,5 @@ hhh
cuowu
true
false
false
false

View File

@ -77,4 +77,11 @@ var proxy = new Proxy(person, {
print(proxy.name);
print(proxy.age);
print(proxy.hasOwnProperty('name'));
print(proxy.hasOwnProperty('age'));
print(proxy.hasOwnProperty('age'));
let obj2 = {};
obj2.property1 = 12;
// is not intern string branch and not found in intern string table
print(obj2.hasOwnProperty(String.fromCodePoint("")));
// is not intern string branch and found in intern string table
print(obj2.hasOwnProperty(String.fromCodePoint(123)));