mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
Array元素是String类型,优化toSorted速度
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAWHSX Signed-off-by: jiangmengyang <jiangmengyang3@huawei.com> Change-Id: I7e0563846346f84718e0a1d8c6a3fc47a076ef80
This commit is contained in:
parent
9bfd506c07
commit
b1e8ec8184
@ -1544,17 +1544,42 @@ GateRef BuiltinsArrayStubBuilder::DoSort(GateRef glue, GateRef receiver, GateRef
|
||||
Bind(&afterGettingmiddleValue);
|
||||
{
|
||||
Label isInt(env);
|
||||
Label notInt(env);
|
||||
Label exchangeIndex(env);
|
||||
GateRef middleVal = *middleValue;
|
||||
GateRef presentVal = *presentValue;
|
||||
BRANCH(LogicAndBuilder(env).And(TaggedIsInt(middleVal)).And(TaggedIsInt(presentVal)).Done(),
|
||||
&isInt, slowPath);
|
||||
DEFVARIABLE(compareResult, VariableType::INT32(), Int32(0));
|
||||
GateRef intBool = LogicAndBuilder(env)
|
||||
.And(TaggedIsInt(middleVal))
|
||||
.And(TaggedIsInt(presentVal))
|
||||
.Done();
|
||||
BRANCH(intBool, &isInt, ¬Int);
|
||||
Bind(&isInt);
|
||||
{
|
||||
GateRef compareResult =
|
||||
compareResult =
|
||||
CallNGCRuntime(glue, RTSTUB_ID(FastArraySort), {*middleValue, *presentValue});
|
||||
Jump(&exchangeIndex);
|
||||
}
|
||||
Bind(¬Int);
|
||||
{
|
||||
Label isString(env);
|
||||
GateRef strBool = LogicAndBuilder(env)
|
||||
.And(TaggedIsString(middleVal))
|
||||
.And(TaggedIsString(presentVal))
|
||||
.Done();
|
||||
BRANCH(strBool, &isString, slowPath);
|
||||
Bind(&isString);
|
||||
{
|
||||
compareResult = CallNGCRuntime(glue,
|
||||
RTSTUB_ID(FastArraySortString), {glue, *middleValue, *presentValue});
|
||||
Jump(&exchangeIndex);
|
||||
}
|
||||
}
|
||||
Bind(&exchangeIndex);
|
||||
{
|
||||
Label less0(env);
|
||||
Label greater0(env);
|
||||
BRANCH(Int32LessThanOrEqual(compareResult, Int32(0)), &less0, &greater0);
|
||||
BRANCH(Int32LessThanOrEqual(*compareResult, Int32(0)), &less0, &greater0);
|
||||
Bind(&greater0);
|
||||
{
|
||||
endIndex = middleIndex;
|
||||
|
@ -1744,6 +1744,21 @@ DEF_CALL_SIGNATURE(FastArraySort)
|
||||
callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC);
|
||||
}
|
||||
|
||||
DEF_CALL_SIGNATURE(FastArraySortString)
|
||||
{
|
||||
// 2 : 2 input parameters
|
||||
CallSignature fastArraySortString("FastArraySortString", 0, 2,
|
||||
ArgumentsOrder::DEFAULT_ORDER, VariableType::INT32());
|
||||
*callSign = fastArraySortString;
|
||||
std::array<VariableType, 3> params = { // 3 : 3 input parameters
|
||||
VariableType::NATIVE_POINTER(),
|
||||
VariableType::JS_ANY(),
|
||||
VariableType::JS_ANY()
|
||||
};
|
||||
callSign->SetParameters(params.data());
|
||||
callSign->SetGCLeafFunction(true);
|
||||
callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC);
|
||||
}
|
||||
DEF_CALL_SIGNATURE(StringToNumber)
|
||||
{
|
||||
// 4 : 4 input parameters
|
||||
|
@ -591,6 +591,7 @@ private:
|
||||
V(NumberHelperStringToDouble) \
|
||||
V(GetStringToListCacheArray) \
|
||||
V(FastArraySort) \
|
||||
V(FastArraySortString) \
|
||||
V(StringToNumber) \
|
||||
V(StringGetStart) \
|
||||
V(StringGetEnd) \
|
||||
|
@ -185,6 +185,7 @@ namespace panda::ecmascript {
|
||||
V(NumberHelperStringToDouble) \
|
||||
V(GetStringToListCacheArray) \
|
||||
V(FastArraySort) \
|
||||
V(FastArraySortString) \
|
||||
V(StringToNumber) \
|
||||
V(StringGetStart) \
|
||||
V(StringGetEnd) \
|
||||
|
@ -3851,6 +3851,15 @@ int RuntimeStubs::FastArraySort(JSTaggedType x, JSTaggedType y)
|
||||
return JSTaggedValue::IntLexicographicCompare(JSTaggedValue(x), JSTaggedValue(y));
|
||||
}
|
||||
|
||||
int RuntimeStubs::FastArraySortString(uintptr_t argGlue, JSTaggedValue x, JSTaggedValue y)
|
||||
{
|
||||
DISALLOW_GARBAGE_COLLECTION;
|
||||
auto thread = JSThread::GlueToJSThread(argGlue);
|
||||
JSHandle<EcmaString> valueX(thread, x);
|
||||
JSHandle<EcmaString> valueY(thread, y);
|
||||
return static_cast<int>(EcmaStringAccessor::Compare(thread->GetEcmaVM(), valueX, valueY));
|
||||
}
|
||||
|
||||
DEF_RUNTIME_STUBS(LocaleCompareCacheable)
|
||||
{
|
||||
RUNTIME_STUBS_HEADER(LocaleCompareCacheable);
|
||||
|
@ -143,6 +143,7 @@ public:
|
||||
static JSTaggedValue NumberHelperStringToDouble(EcmaString *str);
|
||||
static JSTaggedValue GetStringToListCacheArray(uintptr_t argGlue);
|
||||
static int FastArraySort(JSTaggedType x, JSTaggedType y);
|
||||
static int FastArraySortString(uintptr_t argGlue, JSTaggedValue x, JSTaggedValue y);
|
||||
static JSTaggedValue StringToNumber(JSTaggedType numberString, int32_t radix);
|
||||
static void ArrayTrim(uintptr_t argGlue, TaggedArray *array, int64_t newLength);
|
||||
static double TimeClip(double time);
|
||||
|
@ -340,4 +340,39 @@ arr.sort();
|
||||
//for cmp return type is double
|
||||
let arr34 = [2.63, 1.67];
|
||||
print(arr34.sort((a, b)=> a - b));
|
||||
print("sort Test Success!")
|
||||
print("sort Test Success!");
|
||||
|
||||
// String toSorted
|
||||
{
|
||||
let array1 = new Array();
|
||||
for (let i = 0; i < 1; i++) array1[i] = `string.${i}`;
|
||||
print(array1.toSorted());
|
||||
|
||||
array1 = new Array();
|
||||
for (let i = 0; i < 2; i++) array1[i] = `string.${i}`;
|
||||
print(array1.toSorted());
|
||||
|
||||
array1 = new Array();
|
||||
for (let i = 0; i < 2; i++) array1[i] = `string.${1 - i}`;
|
||||
print(array1.toSorted());
|
||||
|
||||
array1 = new Array();
|
||||
array1[0] = `a`;
|
||||
array1[1] = `b`;
|
||||
array1[2] = `c`;
|
||||
array1[3] = `d`;
|
||||
array1[4] = `e`;
|
||||
array1[5] = `f`;
|
||||
array1[6] = `g`;
|
||||
print(array1.toSorted());
|
||||
|
||||
array1 = new Array();
|
||||
array1[6] = `a`;
|
||||
array1[5] = `b`;
|
||||
array1[4] = `c`;
|
||||
array1[3] = `d`;
|
||||
array1[2] = `e`;
|
||||
array1[1] = `f`;
|
||||
array1[0] = `g`;
|
||||
print(array1.toSorted());
|
||||
}
|
||||
|
@ -54,3 +54,8 @@ This is not a TypedArray.
|
||||
[{"name":"Eagle","grade":13},{"name":"Sam","grade":14},{"name":"Alex","grade":15},{"name":"Devlin","grade":15}]
|
||||
1.67,2.63
|
||||
sort Test Success!
|
||||
string.0
|
||||
string.0,string.1
|
||||
string.0,string.1
|
||||
a,b,c,d,e,f,g
|
||||
a,b,c,d,e,f,g
|
||||
|
Loading…
Reference in New Issue
Block a user