mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
perf(encoding): avoid copying the input data in TextDecoder
(#12573)
The implementation of `TextDecoder` had a bug where it was copying the input data in every case. This change removes that copy in non-`SharedArrayBuffer` cases. Since passing a shared buffer source to Rust would fail, this copy of the input data was making `TextDecoder` work in cases where the input is shared. In order to avoid a breaking change, the copy is retained in those cases.
This commit is contained in:
parent
117d9d2087
commit
507ab50e0f
1 changed files with 8 additions and 1 deletions
|
@ -114,7 +114,14 @@
|
|||
} else {
|
||||
input = new Uint8Array(input);
|
||||
}
|
||||
return core.opSync("op_encoding_decode", new Uint8Array(input), {
|
||||
if (input.buffer instanceof SharedArrayBuffer) {
|
||||
// We clone the data into a non-shared ArrayBuffer so we can pass it
|
||||
// to Rust.
|
||||
// `input` is now a Uint8Array, and calling the TypedArray constructor
|
||||
// with a TypedArray argument copies the data.
|
||||
input = new Uint8Array(input);
|
||||
}
|
||||
return core.opSync("op_encoding_decode", input, {
|
||||
rid: this.#rid,
|
||||
stream: options.stream,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue