Skip to content

Commit 64af28e

Browse files
Skip re-creating DataView in decodeArray
1 parent 78b442d commit 64af28e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Runtime/src/js-value.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ export const decode = (
5252
// `decodeValues` assumes that the size of RawJSValue is 16.
5353
export const decodeArray = (ptr: pointer, length: number, memory: Memory) => {
5454
let result = [];
55+
// It's safe to hold DataView here because WebAssembly.Memory.buffer won't
56+
// change within this function.
57+
const view = memory.dataView();
5558
for (let index = 0; index < length; index++) {
5659
const base = ptr + 16 * index;
57-
const kind = memory.readUint32(base);
58-
const payload1 = memory.readUint32(base + 4);
59-
const payload2 = memory.readFloat64(base + 8);
60+
const kind = view.getUint32(base, true);
61+
const payload1 = view.getUint32(base + 4, true);
62+
const payload2 = view.getFloat64(base + 8, true);
6063
result.push(decode(kind, payload1, payload2, memory));
6164
}
6265
return result;

0 commit comments

Comments
 (0)