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 stdout buffer allocation #967

Merged
merged 1 commit into from
Mar 13, 2021
Merged

Conversation

jridgewell
Copy link
Contributor

Your comment reminded me to fix this one, too.

@maysupan
Copy link

Thank!

@@ -434,7 +434,7 @@ export function createChannel(streamIn: StreamIn): StreamOut {
break;
}
offset += 4;
handleIncomingPacket(stdout.slice(offset, offset + length));
handleIncomingPacket(stdout.subarray(offset, offset + length));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concern here is that something later on would save a copy of some subarray of this subarray, which could then get overwritten later. But I checked the decoding code and it appears to always make a copy, so this should be ok I think:

read(): Uint8Array {
let length = this.read32();
let bytes = new Uint8Array(length);
let ptr = this._read(bytes.length);
bytes.set(this.buf.subarray(ptr, ptr + length));
return bytes;
}

@evanw evanw merged commit dad0925 into evanw:master Mar 13, 2021
@jridgewell jridgewell deleted the stdout-subarray branch March 13, 2021 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants