!9640 Regexp Flags属性字符串生成优化

Merge pull request !9640 from jiangmengyang/getflags2
This commit is contained in:
openharmony_ci 2024-10-12 13:30:10 +00:00 committed by Gitee
commit 4d7faec6d2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 78 additions and 37 deletions

View File

@ -26,8 +26,8 @@ void BuiltinsRegExpStubBuilder::GetFlags(GateRef glue, GateRef thisValue,
BRANCH(IsEcmaObject(thisValue), &isEcmaObject, slowPath);
Bind(&isEcmaObject);
Label fastRegExpPath(env);
GateRef fastRegExp = CallRuntime(glue, RTSTUB_ID(IsFastRegExp), { thisValue });
BRANCH(TaggedIsTrue(fastRegExp), slowPath, &fastRegExpPath);
GateRef fastRegExp = CallNGCRuntime(glue, RTSTUB_ID(IsFastRegExp), {glue, thisValue});
BRANCH(fastRegExp, slowPath, &fastRegExpPath);
Bind(&fastRegExpPath);
{
Label hasException(env);

View File

@ -1820,6 +1820,21 @@ DEF_CALL_SIGNATURE(StringGetEnd)
callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC);
}
DEF_CALL_SIGNATURE(IsFastRegExp)
{
// 3 : 3 input parameters
CallSignature isFastRegExp("IsFastRegExp", 0, 2,
ArgumentsOrder::DEFAULT_ORDER, VariableType::BOOL());
*callSign = isFastRegExp;
std::array<VariableType, 2> params = { // 2 : 2 input parameters
VariableType::NATIVE_POINTER(),
VariableType::JS_ANY()
};
callSign->SetParameters(params.data());
callSign->SetGCLeafFunction(true);
callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC);
}
#define PUSH_CALL_ARGS_AND_DISPATCH_SIGNATURE_COMMON(name) \
/* 1 : 1 input parameters */ \
CallSignature signature(#name, 0, 1, \

View File

@ -630,7 +630,8 @@ private:
V(ConvertCharToDouble) \
V(ASMFastWriteBarrier) \
V(ASMWriteBarrierWithEden) \
V(VerifyBarrier)
V(VerifyBarrier) \
V(IsFastRegExp)
#define DECL_CALL_SIGNATURE(name) \
class name##CallSignature final { \

View File

@ -189,7 +189,8 @@ namespace panda::ecmascript {
V(StringGetStart) \
V(StringGetEnd) \
V(ArrayTrim) \
V(CopyTypedArrayBuffer)
V(CopyTypedArrayBuffer) \
V(IsFastRegExp)
#define RUNTIME_STUB_WITH_GC_LIST(V) \
V(AddElementInternal) \
@ -480,7 +481,6 @@ namespace panda::ecmascript {
V(OptSuperCallForwardAllArgs) \
V(GetCollationValueFromIcuCollator) \
V(DecodeURIComponent) \
V(IsFastRegExp) \
V(GetAllFlagsInternal)

View File

@ -3882,6 +3882,15 @@ void RuntimeStubs::ArrayTrim(uintptr_t argGlue, TaggedArray *array, int64_t newL
array->Trim(thread, length);
}
bool RuntimeStubs::IsFastRegExp(uintptr_t argGlue, JSTaggedValue thisValue)
{
DISALLOW_GARBAGE_COLLECTION;
auto thread = JSThread::GlueToJSThread(argGlue);
[[maybe_unused]] EcmaHandleScope handleScope(thread);
JSHandle<JSTaggedValue> thisObjVal(thread, thisValue);
return builtins::BuiltinsRegExp::IsFastRegExp(thread, thisObjVal);
}
DEF_RUNTIME_STUBS(ArrayForEachContinue)
{
RUNTIME_STUBS_HEADER(ArrayForEachContinue);
@ -4050,58 +4059,37 @@ DEF_RUNTIME_STUBS(GetCollationValueFromIcuCollator)
return thread->GlobalConstants()->GetDefaultString().GetRawData();
}
DEF_RUNTIME_STUBS(IsFastRegExp)
{
RUNTIME_STUBS_HEADER(IsFastRegExp);
JSHandle<JSObject> thisValue = GetHArg<JSObject>(argv, argc, 0); // 0: means the zeroth parameter
JSHandle<JSTaggedValue> thisObjVal(thisValue);
bool result = builtins::BuiltinsRegExp::IsFastRegExp(thread, thisObjVal);
return JSTaggedValue(result).GetRawData();
}
DEF_RUNTIME_STUBS(GetAllFlagsInternal)
{
RUNTIME_STUBS_HEADER(GetAllFlagsInternal);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
uint8_t *flagsStr = new uint8_t[RegExpParser::FLAG_NUM + 1]; // FLAG_NUM flags + '\0'
if (flagsStr == nullptr) {
LOG_ECMA(FATAL) << "BuiltinsRegExp::GetAllFlagsInternal:flagsStr is nullptr";
}
size_t flagsLen = 0;
JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
int64 bigFlagsStr = value->GetInt();
std::string strFlags = "";
strFlags.reserve(RegExpParser::FLAG_NUM);
if (bigFlagsStr & RegExpParser::FLAG_HASINDICES) {
flagsStr[flagsLen] = 'd';
flagsLen++;
strFlags += "d";
}
if (bigFlagsStr & RegExpParser::FLAG_GLOBAL) {
flagsStr[flagsLen] = 'g';
flagsLen++;
strFlags += "g";
}
if (bigFlagsStr & RegExpParser::FLAG_IGNORECASE) {
flagsStr[flagsLen] = 'i';
flagsLen++;
strFlags += "i";
}
if (bigFlagsStr & RegExpParser::FLAG_MULTILINE) {
flagsStr[flagsLen] = 'm';
flagsLen++;
strFlags += "m";
}
if (bigFlagsStr & RegExpParser::FLAG_DOTALL) {
flagsStr[flagsLen] = 's';
flagsLen++;
strFlags += "s";
}
if (bigFlagsStr & RegExpParser::FLAG_UTF16) {
flagsStr[flagsLen] = 'u';
flagsLen++;
strFlags += "u";
}
if (bigFlagsStr & RegExpParser::FLAG_STICKY) {
flagsStr[flagsLen] = 'y';
flagsLen++;
strFlags += "y";
}
flagsStr[flagsLen] = '\0';
JSHandle<EcmaString> flagsString = factory->NewFromUtf8(flagsStr, flagsLen);
delete[] flagsStr;
JSHandle<EcmaString> flagsString = factory->NewFromUtf8(std::string_view(strFlags));
return flagsString.GetTaggedValue().GetRawData();
}

View File

@ -532,6 +532,8 @@ private:
int32_t strLen);
static inline JSTaggedValue UTF16EncodeCodePoint(JSThread *thread, const std::vector<uint8_t> &oct,
const JSHandle<EcmaString> &str, std::u16string &sStr);
static inline bool IsFastRegExp(uintptr_t argGlue, JSTaggedValue thisValue);
static inline uint8_t GetValueFromTwoHex(uint8_t front, uint8_t behind);
friend class SlowRuntimeStub;
};

View File

@ -168,3 +168,11 @@ true
true
true
dgimsuy
g
gi
gy
gm
gs
gu
dg
g

View File

@ -696,6 +696,33 @@ print(1 == result.length);
print('9' == result[0]);
// test getFlags
Object.defineProperty(RegExp.prototype, "global", {
value: true
})
const res = /abc/giymsud;
res.lastIndex = -1;
print(res.flags);
const res1 = /abc/g;
res1.lastIndex = -1;
print(res1.flags);
const res2 = /abc/i;
res2.lastIndex = -1;
print(res2.flags);
const res3 = /abc/y;
res3.lastIndex = -1;
print(res3.flags);
const res4 = /abc/m;
res4.lastIndex = -1;
print(res4.flags);
const res5 = /abc/s;
res5.lastIndex = -1;
print(res5.flags);
const res6 = /abc/u;
res6.lastIndex = -1;
print(res6.flags);
const res7 = /abc/d;
res7.lastIndex = -1;
print(res7.flags);
const res8 = /abc/;
res8.lastIndex = -1;
print(res8.flags);