summaryrefslogtreecommitdiff
path: root/ext/web/08_text_encoding.js
diff options
context:
space:
mode:
authorrandomicon00 <20146907+randomicon00@users.noreply.github.com>2022-05-17 14:52:48 +0100
committerGitHub <noreply@github.com>2022-05-17 19:22:48 +0530
commite58f77e431c7f9404bd76f6b7cf5b6d7841c0b0f (patch)
treeba49dbb466b24c7816ba1424ad11d7292d9340ef /ext/web/08_text_encoding.js
parent8879244f72aebd2fd4d3ae34a064ff04069a6b58 (diff)
perf(ext/web): Add fast path for non-streaming TextDecoder (#14217)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'ext/web/08_text_encoding.js')
-rw-r--r--ext/web/08_text_encoding.js28
1 files changed, 17 insertions, 11 deletions
diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js
index 4f26089b1..86ac5ab3c 100644
--- a/ext/web/08_text_encoding.js
+++ b/ext/web/08_text_encoding.js
@@ -95,16 +95,6 @@
context: "Argument 2",
});
- // TODO(lucacasonato): add fast path for non-streaming decoder & decode
-
- if (this.#rid === null) {
- this.#rid = core.opSync("op_encoding_new_decoder", {
- label: this.#encoding,
- fatal: this.#fatal,
- ignoreBom: this.#ignoreBOM,
- });
- }
-
try {
try {
if (ArrayBufferIsView(input)) {
@@ -132,12 +122,28 @@
// with a TypedArray argument copies the data.
input = new Uint8Array(input);
}
+
+ if (!options.stream && this.#rid === null) {
+ return core.opSync("op_encoding_decode_single", input, {
+ label: this.#encoding,
+ fatal: this.#fatal,
+ ignoreBom: this.#ignoreBOM,
+ });
+ }
+
+ if (this.#rid === null) {
+ this.#rid = core.opSync("op_encoding_new_decoder", {
+ label: this.#encoding,
+ fatal: this.#fatal,
+ ignoreBom: this.#ignoreBOM,
+ });
+ }
return core.opSync("op_encoding_decode", input, {
rid: this.#rid,
stream: options.stream,
});
} finally {
- if (!options.stream) {
+ if (!options.stream && this.#rid) {
core.close(this.#rid);
this.#rid = null;
}