From cca70ae5edc2490acf092d26d8a9689474aed8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Pasi=C5=84ski?= Date: Fri, 28 Jun 2024 10:31:04 +0200 Subject: [PATCH] chore: use memcpy to copy elements --- lib/VM/JSLib/TypedArray.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/VM/JSLib/TypedArray.cpp b/lib/VM/JSLib/TypedArray.cpp index 7a1f5261580..d4011e4f072 100644 --- a/lib/VM/JSLib/TypedArray.cpp +++ b/lib/VM/JSLib/TypedArray.cpp @@ -1761,8 +1761,8 @@ typedArrayPrototypeToReversed(void *, Runtime &runtime, NativeArgs args) { auto self = args.vmcastThis(); // 3. Let len be O.[[ArrayLength]]. - JSArrayBuffer::size_type len = self->getLength(); - + auto len = self->getLength(); + auto byteLength = self->getByteLength(); auto byteWidth = self->getByteWidth(); // 4. Let A be ? TypedArrayCreateSameType(O, « 𝔽(len) »). @@ -1775,19 +1775,19 @@ typedArrayPrototypeToReversed(void *, Runtime &runtime, NativeArgs args) { // 5. Let k be 0. JSArrayBuffer::size_type k = 0; - auto aBuffer = A->getBuffer(runtime); - auto srcBuffer = self->getBuffer(runtime); + auto dstBlock = A->getBuffer(runtime)->getDataBlock(runtime); + auto srcBlock = self->getBuffer(runtime)->getDataBlock(runtime); // 6. Repeat, while k < len, - while (k < len) { + while (k < byteLength) { // 6a. Let from be ! ToString(𝔽(length - k - 1)). - JSArrayBuffer::size_type from = len - k - 1; + size_t from = byteLength - k - byteWidth; // 6d. Perform ! Set(A, Pk, fromValue, true). - JSArrayBuffer::copyDataBlockBytes(runtime, aBuffer, k * byteWidth, srcBuffer, from * byteWidth, byteWidth); + memcpy(dstBlock + k, srcBlock + from, byteWidth); // 6e. Set k to k + 1. - ++k; + k += byteWidth; } return A.getHermesValue();