mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
Opt dataview.setviewvalue
Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I87B09 Signed-off-by: xiaoweidong <xiaoweidong@huawei.com> Change-Id: Id877256649627c747a682addcf4453e09d60b7da
This commit is contained in:
parent
62fd2c6734
commit
758357e0af
@ -360,11 +360,18 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle<JS
|
||||
if (!view->IsDataView()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "view is not dataview", JSTaggedValue::Exception());
|
||||
}
|
||||
// 3. Let numberIndex be ToNumber(requestIndex).
|
||||
JSTaggedNumber numberIndex = JSTaggedValue::ToNumber(thread, requestIndex);
|
||||
// 5. ReturnIfAbrupt(getIndex).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
int32_t indexInt = base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber());
|
||||
|
||||
int32_t indexInt = 0;
|
||||
if (requestIndex->IsInt()) {
|
||||
// fast get index if requestIndex is int
|
||||
indexInt = requestIndex->GetInt();
|
||||
} else {
|
||||
// 3. Let numberIndex be ToNumber(requestIndex).
|
||||
JSTaggedNumber numberIndex = JSTaggedValue::ToNumber(thread, requestIndex);
|
||||
// 5. ReturnIfAbrupt(getIndex).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
indexInt = base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber());
|
||||
}
|
||||
// 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
|
||||
if (indexInt < 0) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex < 0", JSTaggedValue::Exception());
|
||||
@ -415,17 +422,26 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle<JS
|
||||
if (!view->IsDataView()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "view is not dataview", JSTaggedValue::Exception());
|
||||
}
|
||||
// 3. Let numberIndex be ToNumber(requestIndex).
|
||||
JSTaggedNumber numberIndex = JSTaggedValue::ToIndex(thread, requestIndex);
|
||||
// 5. ReturnIfAbrupt(getIndex).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
int64_t index = base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber());
|
||||
int64_t index = 0;
|
||||
if (requestIndex->IsInt()) {
|
||||
// fast get index if requestIndex is int
|
||||
index = requestIndex->GetInt();
|
||||
} else {
|
||||
// 3. Let numberIndex be ToNumber(requestIndex).
|
||||
JSTaggedNumber numberIndex = JSTaggedValue::ToIndex(thread, requestIndex);
|
||||
// 5. ReturnIfAbrupt(getIndex).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
index = base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber());
|
||||
}
|
||||
// 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
|
||||
if (index < 0) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex < 0", JSTaggedValue::Exception());
|
||||
}
|
||||
JSHandle<JSTaggedValue> numValueHandle = JSTaggedValue::ToNumeric(thread, value);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
JSMutableHandle<JSTaggedValue> numValueHandle = JSMutableHandle<JSTaggedValue>(thread, value);
|
||||
if (!value->IsNumber()) {
|
||||
numValueHandle.Update(JSTaggedValue::ToNumeric(thread, value));
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
// 7. Let isLittleEndian be ToBoolean(isLittleEndian).
|
||||
bool isLittleEndian = false;
|
||||
if (littleEndian->IsUndefined()) {
|
||||
|
64
test/perform/dataview/dataview.ts
Normal file
64
test/perform/dataview/dataview.ts
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
declare function print(arg:any) : string;
|
||||
declare interface ArkTools {
|
||||
timeInUs(arg:any):number
|
||||
}
|
||||
|
||||
function testGetVievValue() {
|
||||
var buffer = new ArrayBuffer(8);
|
||||
var dataview = new DataView(buffer);
|
||||
let start = ArkTools.timeInUs();
|
||||
let res;
|
||||
for (let i = 0; i < 1_000_000; i++) {
|
||||
res = dataview.getInt32(2);
|
||||
}
|
||||
let end = ArkTools.timeInUs();
|
||||
let time = (end - start) / 1000
|
||||
print(res)
|
||||
print("DataView GetVievValue:\t" + String(time) + "\tms");
|
||||
}
|
||||
|
||||
function testSetVievValue() {
|
||||
var buffer = new ArrayBuffer(8);
|
||||
var dataview = new DataView(buffer);
|
||||
let start = ArkTools.timeInUs();
|
||||
for (let i = 0; i < 1_000_000; i++) {
|
||||
dataview.setInt32(1, 2);
|
||||
}
|
||||
let end = ArkTools.timeInUs();
|
||||
let time = (end - start) / 1000
|
||||
print("DataView SetVievValue:\t" + String(time) + "\tms");
|
||||
}
|
||||
|
||||
function testGetByteLength() {
|
||||
var buffer = new ArrayBuffer(8);
|
||||
var dataview = new DataView(buffer);
|
||||
let start = ArkTools.timeInUs();
|
||||
let res;
|
||||
for (let i = 0; i < 1_000_000; i++) {
|
||||
res = dataview.byteLength;
|
||||
}
|
||||
let end = ArkTools.timeInUs();
|
||||
let time = (end - start) / 1000
|
||||
print(res)
|
||||
print("DataView ByteLength:\t" + String(time) + "\tms");
|
||||
}
|
||||
|
||||
testSetVievValue();
|
||||
testGetVievValue();
|
||||
testGetByteLength();
|
||||
|
Loading…
Reference in New Issue
Block a user