diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2020-01-04 23:00:03 +0100 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2020-01-04 17:00:03 -0500 |
commit | c41280a057c9ca300afe43f2cb4f576e050f8cde (patch) | |
tree | 40ad9befa29e099c65330213221172ad8d2497d2 /cli/js/text_encoding.ts | |
parent | 0a900949c83503c2af75e8f1ea9bbbc6e947887d (diff) |
perf: TextEncoder.encode improvement (#3596)
Diffstat (limited to 'cli/js/text_encoding.ts')
-rw-r--r-- | cli/js/text_encoding.ts | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/cli/js/text_encoding.ts b/cli/js/text_encoding.ts index 6ca7e642f..ceb2f3fdc 100644 --- a/cli/js/text_encoding.ts +++ b/cli/js/text_encoding.ts @@ -26,6 +26,7 @@ import * as base64 from "./base64.ts"; import { decodeUtf8 } from "./decode_utf8.ts"; import * as domTypes from "./dom_types.ts"; +import { encodeUtf8 } from "./encode_utf8.ts"; import { DenoError, ErrorKind } from "./errors.ts"; const CONTINUE = null; @@ -405,6 +406,12 @@ export class TextEncoder { readonly encoding = "utf-8"; /** Returns the result of running UTF-8's encoder. */ encode(input = ""): Uint8Array { + // For performance reasons we utilise a highly optimised decoder instead of + // the general decoder. + if (this.encoding === "utf-8") { + return encodeUtf8(input); + } + const encoder = new UTF8Encoder(); const inputStream = new Stream(stringToCodePoints(input)); const output: number[] = []; |