mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
Optimize FromCharCode C++ interface
issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I6OVYD?from=project-issue Signed-off-by: dingwen <dingwen6@huawei.com> Change-Id: I73b35dbe413c19eece63ec8e1a1409c01aaf5447
This commit is contained in:
parent
59525cfcdf
commit
fa6d1cde91
@ -101,24 +101,22 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv)
|
||||
if (argLength == 0) {
|
||||
return factory->GetEmptyString().GetTaggedValue();
|
||||
}
|
||||
JSHandle<JSTaggedValue> codePointTag = BuiltinsString::GetCallArg(argv, 0);
|
||||
uint16_t codePointValue = JSTaggedValue::ToUint16(thread, codePointTag);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
JSHandle<EcmaString> strHandle = factory->NewFromUtf16Literal(&codePointValue, 1);
|
||||
if (argLength == 1) {
|
||||
JSHandle<JSTaggedValue> codePointTag = BuiltinsString::GetCallArg(argv, 0);
|
||||
uint16_t codePointValue = JSTaggedValue::ToUint16(thread, codePointTag);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
JSHandle<EcmaString> strHandle = factory->NewFromUtf16Literal(&codePointValue, 1);
|
||||
return strHandle.GetTaggedValue();
|
||||
}
|
||||
std::u16string u16str = base::StringHelper::Utf16ToU16String(&codePointValue, 1);
|
||||
CVector<uint16_t> valueTable;
|
||||
valueTable.reserve(argLength - 1);
|
||||
for (uint32_t i = 1; i < argLength; i++) {
|
||||
valueTable.reserve(argLength);
|
||||
for (uint32_t i = 0; i < argLength; i++) {
|
||||
JSHandle<JSTaggedValue> nextCp = BuiltinsString::GetCallArg(argv, i);
|
||||
uint16_t nextCv = JSTaggedValue::ToUint16(thread, nextCp);
|
||||
valueTable.emplace_back(nextCv);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
std::u16string nextU16str = base::StringHelper::Utf16ToU16String(valueTable.data(), argLength - 1);
|
||||
u16str = base::StringHelper::Append(u16str, nextU16str);
|
||||
std::u16string u16str = base::StringHelper::Utf16ToU16String(valueTable.data(), argLength);
|
||||
const char16_t *constChar16tData = u16str.data();
|
||||
auto *char16tData = const_cast<char16_t *>(constChar16tData);
|
||||
auto *uint16tData = reinterpret_cast<uint16_t *>(char16tData);
|
||||
|
@ -467,8 +467,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver,
|
||||
return JSTaggedValue::Hole();
|
||||
}
|
||||
JSHandle<JSTaggedValue> valueHandle(thread, value);
|
||||
elements = *JSObject::GrowElementsCapacity(thread, receiverHandle,
|
||||
JSObject::ComputeElementCapacity(elementIndex + 1));
|
||||
elements = *JSObject::GrowElementsCapacity(thread, receiverHandle, elementIndex + 1);
|
||||
receiverHandle->SetElements(thread, JSTaggedValue(elements));
|
||||
elements->Set(thread, elementIndex, valueHandle);
|
||||
return JSTaggedValue::Undefined();
|
||||
|
@ -288,8 +288,7 @@ DEF_RUNTIME_STUBS(TaggedArraySetValue)
|
||||
}
|
||||
JSHandle<JSObject> receiverHandle(thread, reinterpret_cast<JSObject *>(argReceiver));
|
||||
JSHandle<JSTaggedValue> valueHandle(thread, value);
|
||||
elements = *JSObject::GrowElementsCapacity(thread, receiverHandle,
|
||||
JSObject::ComputeElementCapacity(elementIndex + 1));
|
||||
elements = *JSObject::GrowElementsCapacity(thread, receiverHandle, elementIndex + 1);
|
||||
receiverHandle->SetElements(thread, JSTaggedValue(elements));
|
||||
elements->Set(thread, elementIndex, valueHandle);
|
||||
return JSTaggedValue::Undefined().GetRawData();
|
||||
|
@ -17,6 +17,10 @@ host_moduletest_action("builtinsir") {
|
||||
deps = []
|
||||
}
|
||||
|
||||
host_moduletest_action("builtinsstring") {
|
||||
deps = []
|
||||
}
|
||||
|
||||
host_moduletest_action("builtinsnumber") {
|
||||
deps = []
|
||||
}
|
||||
@ -27,6 +31,7 @@ host_moduletest_action("builtinsregexp") {
|
||||
|
||||
host_moduletest_action("builtins") {
|
||||
extra_modules = [
|
||||
"builtinsstring",
|
||||
"builtinsir",
|
||||
"builtinsnumber",
|
||||
"builtinsregexp",
|
||||
@ -35,5 +40,6 @@ host_moduletest_action("builtins") {
|
||||
":gen_builtinsir_abc",
|
||||
":gen_builtinsnumber_abc",
|
||||
":gen_builtinsregexp_abc",
|
||||
":gen_builtinsstring_abc",
|
||||
]
|
||||
}
|
||||
|
25
test/moduletest/builtins/builtinsstring.js
Normal file
25
test/moduletest/builtins/builtinsstring.js
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @tc.name:builtinsstring
|
||||
* @tc.desc:test builtins
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6OVYD
|
||||
*/
|
||||
print("builtins string start");
|
||||
print(String.fromCharCode(65));
|
||||
print(String.fromCharCode(65, 66, 66, 65));
|
||||
print("builtins string end");
|
@ -12,6 +12,10 @@
|
||||
# limitations under the License.
|
||||
|
||||
builtins test start
|
||||
builtins string start
|
||||
A
|
||||
ABBA
|
||||
builtins string end
|
||||
builtins ir start
|
||||
112
|
||||
119
|
||||
|
Loading…
Reference in New Issue
Block a user