From e95cccad21d529bf509924354e25d1ad715983c3 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 26 Dec 2020 05:12:02 +0900 Subject: [PATCH] jsutil: Reduce calls of (js.Value).Get (js.Value).Get invokes the string conversion from UTF-8 to UTF-16. This is related to #1438, though this is not a fix in the OpenGL driver. Updates #1438 --- internal/jsutil/buf_js.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/jsutil/buf_js.go b/internal/jsutil/buf_js.go index 5fc7068f5..af5b0c6a0 100644 --- a/internal/jsutil/buf_js.go +++ b/internal/jsutil/buf_js.go @@ -28,27 +28,34 @@ var ( // temporaryArrayBuffer is a temporary buffer used at gl.readPixels or gl.texSubImage2D. // The read data is converted to Go's byte slice as soon as possible. // To avoid often allocating ArrayBuffer, reuse the buffer whenever possible. - temporaryArrayBuffer = arrayBuffer.New(16) + temporaryArrayBuffer = arrayBuffer.New(16) + temporaryArrayBufferByteLength = temporaryArrayBuffer.Get("byteLength") // temporaryUint8Array is a Uint8ArrayBuffer whose underlying buffer is always temporaryArrayBuffer. - temporaryUint8Array = uint8Array.New(temporaryArrayBuffer) + temporaryUint8Array = uint8Array.New(temporaryArrayBuffer) + temporaryUint8ArrayByteLength = temporaryUint8Array.Get("byteLength") // temporaryFloat32Array is a Float32ArrayBuffer whose underlying buffer is always temporaryArrayBuffer. - temporaryFloat32Array = float32Array.New(temporaryArrayBuffer) + temporaryFloat32Array = float32Array.New(temporaryArrayBuffer) + temporaryFloat32ArrayByteLength = temporaryFloat32Array.Get("byteLength") ) func ensureTemporaryArrayBufferSize(byteLength int) { - if bufl := temporaryArrayBuffer.Get("byteLength").Int(); bufl < byteLength { + bufl := temporaryArrayBufferByteLength.Int() + if bufl < byteLength { for bufl < byteLength { bufl *= 2 } temporaryArrayBuffer = arrayBuffer.New(bufl) + temporaryArrayBufferByteLength = temporaryArrayBuffer.Get("byteLength") } - if temporaryUint8Array.Get("byteLength").Int() < temporaryArrayBuffer.Get("byteLength").Int() { + if temporaryUint8ArrayByteLength.Int() < bufl { temporaryUint8Array = uint8Array.New(temporaryArrayBuffer) + temporaryUint8ArrayByteLength = temporaryUint8Array.Get("byteLength") } - if temporaryFloat32Array.Get("byteLength").Int() < temporaryArrayBuffer.Get("byteLength").Int() { + if temporaryFloat32ArrayByteLength.Int() < bufl { temporaryFloat32Array = float32Array.New(temporaryArrayBuffer) + temporaryFloat32ArrayByteLength = temporaryFloat32Array.Get("byteLength") } }