!10177 优化array find index[object]

Merge pull request !10177 from jiangmengyang/findIndex
This commit is contained in:
openharmony_ci 2024-11-11 10:11:47 +00:00 committed by Gitee
commit d6df2dc42c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 89 additions and 18 deletions

View File

@ -6693,6 +6693,41 @@ GateRef StubBuilder::FastEqual(GateRef glue, GateRef left, GateRef right, Profil
}
Bind(&rightIsNotUndefinedOrNull);
{
Label bothString(env);
Label eitherNotString(env);
Label isHeapObject(env);
Label notHeapObject(env);
BRANCH(BitAnd(TaggedIsHeapObject(left), TaggedIsHeapObject(right)), &isHeapObject, &notHeapObject);
Bind(&isHeapObject);
{
Label typeEqual(env);
GateRef leftType = GetObjectType(LoadHClass(left));
GateRef rightType = GetObjectType(LoadHClass(right));
BRANCH(Equal(leftType, rightType), &typeEqual, &notHeapObject);
Bind(&typeEqual);
{
Label eitherNotString1(env);
Label bothBigInt(env);
Label eitherNotBigInt(env);
BRANCH(BothAreString(left, right), &bothString, &eitherNotString1);
Bind(&eitherNotString1);
BRANCH(BitAnd(TaggedIsBigInt(left),TaggedIsBigInt(right)), &bothBigInt, &eitherNotBigInt);
Bind(&bothBigInt);
{
callback.ProfileOpType(TaggedInt(PGOSampleType::BigIntType()));
result =BooleanToTaggedBooleanPtr(CallNGCRuntime(glue,
RTSTUB_ID(BigIntEquals), {left, right}));
Jump(&exit);
}
Bind(&eitherNotBigInt);
{
callback.ProfileOpType(TaggedInt(PGOSampleType::AnyType()));
result = TaggedFalse();
Jump(&exit);
}
}
}
Bind(&notHeapObject);
Label leftIsUndefinedOrNull(env);
Label leftIsNotUndefinedOrNull(env);
BRANCH(TaggedIsUndefinedOrNull(right), &leftIsUndefinedOrNull, &leftIsNotUndefinedOrNull);
@ -6724,26 +6759,24 @@ GateRef StubBuilder::FastEqual(GateRef glue, GateRef left, GateRef right, Profil
}
Bind(&leftNotBoolOrRightNotSpecial);
{
Label bothString(env);
Label eitherNotString(env);
BRANCH(BothAreString(left, right), &bothString, &eitherNotString);
Bind(&bothString);
{
callback.ProfileOpType(TaggedInt(PGOSampleType::StringType()));
Label stringEqual(env);
Label stringNotEqual(env);
BRANCH(FastStringEqual(glue, left, right), &stringEqual, &stringNotEqual);
Bind(&stringEqual);
result = TaggedTrue();
Jump(&exit);
Bind(&stringNotEqual);
result = TaggedFalse();
Jump(&exit);
}
Bind(&eitherNotString);
callback.ProfileOpType(TaggedInt(PGOSampleType::AnyType()));
}
Bind(&bothString);
{
callback.ProfileOpType(TaggedInt(PGOSampleType::StringType()));
Label stringEqual(env);
Label stringNotEqual(env);
BRANCH(FastStringEqual(glue, left, right), &stringEqual, &stringNotEqual);
Bind(&stringEqual);
result = TaggedTrue();
Jump(&exit);
Bind(&stringNotEqual);
result = TaggedFalse();
Jump(&exit);
}
Bind(&eitherNotString);
callback.ProfileOpType(TaggedInt(PGOSampleType::AnyType()));
Jump(&exit);
}
}
}

View File

@ -2032,4 +2032,36 @@ try {
arr_push.push(3);
} catch (e) {
print(e instanceof TypeError);
}
}
// find index object
let findIndexArray = new Array(4);
const obj0 = { ["obj0"]: 0 };
const obj1 = { ["obj1"]: 1 };
const obj2 = { ["obj2"]: 2 };
const obj3 = { ["obj3"]: 3 };
findIndexArray[0] = obj0;
findIndexArray[1] = obj1;
findIndexArray[2] = obj2;
findIndexArray[3] = obj3;
print(findIndexArray.findIndex(element => element == obj1));
print(findIndexArray.findIndex(element => element == { ["obj3"]: 3 }));
// find index bigint
findIndexArray = new Array(4);
findIndexArray[0] = 1n;
findIndexArray[1] = 2n;
findIndexArray[2] = 3n;
findIndexArray[3] = 4n;
print(findIndexArray.findIndex(element => element == 2n));
print(findIndexArray.findIndex(element => element == 0n));
// find index string
findIndexArray = new Array(4);
findIndexArray[0] = "a";
findIndexArray[1] = "b";
findIndexArray[2] = "c";
findIndexArray[3] = "d";
print(findIndexArray.findIndex(element => element == "b"));
print(findIndexArray.findIndex(element => element == "e"));

View File

@ -559,3 +559,9 @@ false
false
false
true
1
-1
1
-1
1
-1