!9251 Optimizing ArrayBufferData pointer obtaining

Merge pull request !9251 from hlm2001/hlm_kexin0911_br
This commit is contained in:
openharmony_ci 2024-09-23 03:32:39 +00:00 committed by Gitee
commit 5902e505c9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 9 additions and 4 deletions

View File

@ -327,9 +327,9 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa
JSHandle<JSArrayBuffer> newArrBuf(thread, taggedBuf);
// Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, cloneLength).
// 7. Let srcBlock be the value of srcBuffers [[ArrayBufferData]] internal slot.
if (cloneLen > 0) {
void *fromBuf = GetDataPointFromBuffer(srcBuffer.GetTaggedValue());
void *toBuf = GetDataPointFromBuffer(taggedBuf);
if (cloneLen > 0) {
JSArrayBuffer::CopyDataPointBytes(toBuf, fromBuf, srcByteOffset, cloneLen);
}
return taggedBuf;
@ -781,9 +781,11 @@ void *BuiltinsArrayBuffer::GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t
JSArrayBuffer *arrayBuffer = JSArrayBuffer::Cast(arrBuf.GetTaggedObject());
if (arrayBuffer == nullptr) {
LOG_ECMA(FATAL) << "BuiltinsArrayBuffer::GetDataPointFromBuffer:arrayBuffer is nullptr";
UNREACHABLE();
}
if (arrayBuffer->GetArrayBufferByteLength() == 0) {
return nullptr;
LOG_ECMA(FATAL) << "BuiltinsArrayBuffer::GetDataPointFromBuffer:arrayBuffer length is 0";
UNREACHABLE();
}
JSTaggedValue data = arrayBuffer->GetArrayBufferData();

View File

@ -258,6 +258,9 @@ void RuntimeStubs::CopyTypedArrayBuffer(JSTypedArray *srcArray, JSTypedArray *ta
int32_t tarStartPos, int32_t count, int32_t elementSize)
{
DISALLOW_GARBAGE_COLLECTION;
if (count <= 0) {
return;
}
JSTaggedValue srcBuffer = srcArray->GetViewedArrayBufferOrByteArray();
JSTaggedValue targetBuffer = targetArray->GetViewedArrayBufferOrByteArray();
uint32_t srcByteIndex = static_cast<uint32_t>(srcStartPos * elementSize + srcArray->GetByteOffset());
@ -265,7 +268,7 @@ void RuntimeStubs::CopyTypedArrayBuffer(JSTypedArray *srcArray, JSTypedArray *ta
uint8_t *srcBuf = (uint8_t *)builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(srcBuffer, srcByteIndex);
uint8_t *targetBuf = (uint8_t *)builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(targetBuffer,
targetByteIndex);
if (count > 0 && memmove_s(targetBuf, elementSize * count, srcBuf, elementSize * count) != EOK) {
if (memmove_s(targetBuf, elementSize * count, srcBuf, elementSize * count) != EOK) {
LOG_FULL(FATAL) << "memmove_s failed";
UNREACHABLE();
}