Skip to content

Commit 0d57262

Browse files
committed
[library_sockfs.js] Cleanup buffer handling in sendmsg
Extracting the `buffer.slice` expression made the code cleanup and showed the double `new Uint8Array` to be redundant (AFAICT).
1 parent eff9671 commit 0d57262

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/library_sockfs.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,16 +619,13 @@ addToLibrary({
619619
buffer = buffer.buffer;
620620
}
621621

622-
var data;
623-
#if PTHREADS
624-
// WebSockets .send() does not allow passing a SharedArrayBuffer, so clone the portion of the SharedArrayBuffer as a regular
625-
// ArrayBuffer that we want to send.
626-
if (buffer instanceof SharedArrayBuffer) {
627-
data = new Uint8Array(new Uint8Array(buffer.slice(offset, offset + length))).buffer;
628-
} else {
629-
#endif
630-
data = buffer.slice(offset, offset + length);
622+
var data = buffer.slice(offset, offset + length);
631623
#if PTHREADS
624+
// WebSockets .send() does not allow passing a SharedArrayBuffer, so
625+
// clone the the SharedArrayBuffer as regular ArrayBuffer before
626+
// sending.
627+
if (data instanceof SharedArrayBuffer) {
628+
data = new Uint8Array(data).buffer;
632629
}
633630
#endif
634631

0 commit comments

Comments
 (0)