From 8c80df939f92a9b554269315c0a0835436459015 Mon Sep 17 00:00:00 2001 From: zhuzhengjun Date: Tue, 9 Jan 2024 17:33:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ByteBuffer=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuzhengjun --- .../flutter/src/main/ets/util/ByteBuffer.ets | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/ByteBuffer.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/ByteBuffer.ets index 38d652b936..57193e339a 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/ByteBuffer.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/ByteBuffer.ets @@ -86,11 +86,7 @@ export class ByteBuffer { } get buffer(): ArrayBuffer { - const dataBuffer = new DataView(new ArrayBuffer(this.mByteOffset)); - for (let i = 0; i < this.mByteOffset; i++) { - dataBuffer.setUint8(i, this.dataView!.getUint8(i)); - } - return dataBuffer.buffer + return this.dataView!.buffer.slice(0, this.mByteOffset) } /** @@ -120,11 +116,12 @@ export class ByteBuffer { */ checkWriteCapacity(slen: number): void { if (this.mByteOffset + slen > this.dataView!.byteLength) { - let checkBuffer = new DataView(new ArrayBuffer(this.dataView!.byteLength + slen + 512)); - for (let i = 0; i < this.mByteOffset; i++) { - checkBuffer.setUint8(i, this.dataView!.getUint8(i)); - } - this.dataView = checkBuffer; + let newBuffer = new ArrayBuffer(this.dataView!.byteLength + slen + 512); + let newDataView = new DataView(newBuffer); + let oldUint8Array = new Uint8Array(this.dataView!.buffer); + let newUint8Array = new Uint8Array(newBuffer); + newUint8Array.set(oldUint8Array); + this.dataView = newDataView; } } -- Gitee