Skip to content

Commit

Permalink
Skip re-creating DataView in decodeArray
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Aug 16, 2022
1 parent 78b442d commit bffe009
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Runtime/src/js-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ export const decode = (
// Note:
// `decodeValues` assumes that the size of RawJSValue is 16.
export const decodeArray = (ptr: pointer, length: number, memory: Memory) => {
// fast path for empty array
if (length === 0) { return []; }

let result = [];
// It's safe to hold DataView here because WebAssembly.Memory.buffer won't
// change within this function.
const view = memory.dataView();
for (let index = 0; index < length; index++) {
const base = ptr + 16 * index;
const kind = memory.readUint32(base);
const payload1 = memory.readUint32(base + 4);
const payload2 = memory.readFloat64(base + 8);
const kind = view.getUint32(base, true);
const payload1 = view.getUint32(base + 4, true);
const payload2 = view.getFloat64(base + 8, true);
result.push(decode(kind, payload1, payload2, memory));
}
return result;
Expand Down

0 comments on commit bffe009

Please sign in to comment.