perf(web): optimize encodeInto() (#15922)

This commit is contained in:
Divy Srivastava 2022-09-17 16:48:15 +05:30 committed by GitHub
parent 6154188786
commit 5fe660ecd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 126 additions and 164 deletions

View file

@ -25,6 +25,7 @@
TypedArrayPrototypeSubarray,
TypedArrayPrototypeSlice,
Uint8Array,
Uint32Array,
} = window.__bootstrap.primordials;
class TextDecoder {
@ -199,10 +200,16 @@
context: "Argument 2",
allowShared: true,
});
return ops.op_encoding_encode_into(source, destination);
ops.op_encoding_encode_into(source, destination, encodeIntoBuf);
return {
read: encodeIntoBuf[0],
written: encodeIntoBuf[1],
};
}
}
const encodeIntoBuf = new Uint32Array(2);
webidl.configurePrototype(TextEncoder);
const TextEncoderPrototype = TextEncoder.prototype;