!9535 优化normalize 获取静态常量

Merge pull request !9535 from jiangmengyang/normalize
This commit is contained in:
openharmony_ci 2024-09-29 12:32:13 +00:00 committed by Gitee
commit c0b4ad5d18
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 15 additions and 9 deletions

View File

@ -898,7 +898,6 @@ JSTaggedValue BuiltinsString::Normalize(EcmaRuntimeCallInfo *argv)
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
auto vm = thread->GetEcmaVM();
ObjectFactory *factory = vm->GetFactory();
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
@ -915,18 +914,22 @@ JSTaggedValue BuiltinsString::Normalize(EcmaRuntimeCallInfo *argv)
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
}
}
JSHandle<EcmaString> nfc = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNfcString());
JSHandle<EcmaString> nfd = factory->NewFromASCII("NFD");
JSHandle<EcmaString> nfkc = factory->NewFromASCII("NFKC");
JSHandle<EcmaString> nfkd = factory->NewFromASCII("NFKD");
UNormalizationMode uForm;
if (EcmaStringAccessor::StringsAreEqual(vm, formValue, nfc)) {
if (JSHandle<EcmaString> nfc =
JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNfcString());
EcmaStringAccessor::StringsAreEqual(vm, formValue, nfc)) {
uForm = UNORM_NFC;
} else if (EcmaStringAccessor::StringsAreEqual(vm, formValue, nfd)) {
} else if (JSHandle<EcmaString> nfd =
JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNfdString());
EcmaStringAccessor::StringsAreEqual(vm, formValue, nfd)) {
uForm = UNORM_NFD;
} else if (EcmaStringAccessor::StringsAreEqual(vm, formValue, nfkc)) {
} else if (JSHandle<EcmaString> nfkc =
JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNfkcString());
EcmaStringAccessor::StringsAreEqual(vm, formValue, nfkc)) {
uForm = UNORM_NFKC;
} else if (EcmaStringAccessor::StringsAreEqual(vm, formValue, nfkd)) {
} else if (JSHandle<EcmaString> nfkd =
JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledNfkdString());
EcmaStringAccessor::StringsAreEqual(vm, formValue, nfkd)) {
uForm = UNORM_NFKD;
} else {
THROW_RANGE_ERROR_AND_RETURN(thread, "compare not equal", JSTaggedValue::Exception());

View File

@ -562,6 +562,9 @@ class ObjectFactory;
V(FlagsString, FLAGS_INDEX, "flags") \
V(GString, G_INDEX, "g") \
V(NfcString, NFC_INDEX, "NFC") \
V(NfdString, NFD_INDEX, "NFD") \
V(NfkcString, NFKC_INDEX, "NFKC") \
V(NfkdString, NFKD_INDEX, "NFKD") \
V(EntriesString, ENTRIES_INDEX, "entries") \
V(LeftSquareBracketString, LEFT_SQUARE_BRACKET_INDEX, "[") \
V(RightSquareBracketString, RIGHT_SQUARE_BRACKET_INDEX, "]") \