Skip to content

Commit

Permalink
perf: set state with .subarray() over .slice() to avoid copy (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
jungomi authored Nov 19, 2024
1 parent d8ea68c commit f625303
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/xxhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function xxhash(instance) {

// Each time we interact with wasm, it may have mutated our state so we'll
// need to read it back into our closed copy.
state.set(memory.slice(0, size));
state.set(memory.subarray(0, size));

return {
update(input) {
Expand All @@ -80,7 +80,7 @@ export function xxhash(instance) {
length = input.byteLength;
}
update(0, size, length);
state.set(memory.slice(0, size));
state.set(memory.subarray(0, size));
return this;
},
digest() {
Expand Down

0 comments on commit f625303

Please sign in to comment.