Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid copy of memory for state changes by using .subarray() #49

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

// 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 @@ -89,13 +89,21 @@
length = input.byteLength;
}
update(0, size, length);
state.set(memory.slice(0, size));
state.set(memory.subarray(0, size));
return this;
},
digest() {
memory.set(state);
return finalize(digest(0));
},
reset() {
// Perform the same actions that when it is created
growMemory(size);
state.fill(0);
memory.set(state);
init(0, seed);
state.set(memory.subarray(0, size));
}

Check failure on line 106 in src/index.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Insert `,`

Check failure on line 106 in src/index.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `,`

Check failure on line 106 in src/index.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Insert `,`
};
}

Expand Down
Loading