Skip to content

Commit

Permalink
[library_sockfs.js] Cleanup buffer handling in sendmsg
Browse files Browse the repository at this point in the history
Extracting the `buffer.slice` expression made the code cleanup and
showed the double `new Uint8Array` to be redundant (AFAICT).
  • Loading branch information
sbc100 committed Nov 21, 2024
1 parent eff9671 commit 0d57262
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/library_sockfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,16 +619,13 @@ addToLibrary({
buffer = buffer.buffer;
}

var data;
#if PTHREADS
// WebSockets .send() does not allow passing a SharedArrayBuffer, so clone the portion of the SharedArrayBuffer as a regular
// ArrayBuffer that we want to send.
if (buffer instanceof SharedArrayBuffer) {
data = new Uint8Array(new Uint8Array(buffer.slice(offset, offset + length))).buffer;
} else {
#endif
data = buffer.slice(offset, offset + length);
var data = buffer.slice(offset, offset + length);
#if PTHREADS
// WebSockets .send() does not allow passing a SharedArrayBuffer, so
// clone the the SharedArrayBuffer as regular ArrayBuffer before
// sending.
if (data instanceof SharedArrayBuffer) {
data = new Uint8Array(data).buffer;
}
#endif

Expand Down

0 comments on commit 0d57262

Please sign in to comment.