!7908 Optimize BuiltinsGlobal::Decode when string is tree string

Merge pull request !7908 from chenjingxiang/opt_decodeuri_br
This commit is contained in:
openharmony_ci 2024-06-24 07:41:55 +00:00 committed by Gitee
commit f242284f87
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 17 additions and 2 deletions

View File

@ -458,6 +458,10 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle<EcmaString
// 2. Let R be the empty String.
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
std::u16string resStr;
JSHandle<EcmaString> string = str;
if (EcmaStringAccessor(str).IsTreeString()) {
string = JSHandle<EcmaString>(thread, EcmaStringAccessor::Flatten(thread->GetEcmaVM(), str));
}
// 3. Let k be 0.
// 4. Repeat
@ -483,7 +487,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle<EcmaString
// a. Let S be the String containing only the code unit C.
// 3. Else C is in reservedSet,
// a. Let S be the substring of string from index start to index k inclusive.
uint16_t cc = EcmaStringAccessor(str).Get(k);
uint16_t cc = EcmaStringAccessor(string).Get(k);
std::u16string sStr;
if (cc != '%') {
if (cc == 0 && strLen == 1) {
@ -492,7 +496,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle<EcmaString
}
sStr = StringHelper::Utf16ToU16String(&cc, 1);
} else {
DecodePercentEncoding(thread, str, k, IsInURISet, strLen, sStr);
DecodePercentEncoding(thread, string, k, IsInURISet, strLen, sStr);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
}
resStr.append(sStr);

View File

@ -80,3 +80,9 @@ print(encodeURIComponent(uri11));
print(encodeURIComponent(uri2));
print(encodeURIComponent(uri3));
print(encodeURIComponent(uri4));
print(decodeURIComponent(uri0));
print(decodeURIComponent(uri11));
print(decodeURIComponent(uri2));
print(decodeURIComponent(uri3));
print(decodeURIComponent(uri4));

View File

@ -24,3 +24,8 @@ https%3A%2F%2Fwww.runoob.com%2Fmy%20test.php%3Fname%3Dst%C3%A5le%26car%3Dsaab%2F
https%3A%2F%2Fwww.runoob.com%2Fmy%20test.php%3Fname%3Dst%C3%A5le%26car%3Dsaab%2F2389018203
https%3A%2F%2Fwww.runoob.com%2Fmy%20test.php%3Fname%3Dst%C3%A5le%26car%3Dsaab%2Fjfdlskafasfd%2Fjd2931dsafdsa
https%3A%2F%2Fwww.runoob.com%2Fmy%20test.php%3Fname%3Dst%C3%A5le%26car%3Dsaab%2Fjfdlskafasfd%2Fjd2931dsafdsa%2Fjd2931wjeiojfwre
https://www.runoob.com/my test.php?name=ståle&car=saab
https://www.runoob.com/my test.php?name=ståle&car=saab/jfdlskafasfd
https://www.runoob.com/my test.php?name=ståle&car=saab/2389018203
https://www.runoob.com/my test.php?name=ståle&car=saab/jfdlskafasfd/jd2931dsafdsa
https://www.runoob.com/my test.php?name=ståle&car=saab/jfdlskafasfd/jd2931dsafdsa/jd2931wjeiojfwre