Skip to content

Commit 1ef027b

Browse files
committed
perf: use TextEncoder instead of charCodeAt loop
Use `TypedArray` directly without constructing a new `Blob`.
1 parent 0882bb9 commit 1ef027b

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/ext/background/main.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,11 @@ async function handleMessage(message, sender) {
417417
const user = details.user || null;
418418
const password = details.password || null;
419419
let body = details.data || null;
420+
// deprecate once body supports more data types
421+
// the `binary` key will no longer needed
420422
if (typeof body === "string" && details.binary) {
421-
const len = body.length;
422-
const arr = new Uint8Array(len);
423-
for (let i = 0; i < len; i++) {
424-
arr[i] = body.charCodeAt(i);
425-
}
426-
body = new Blob([arr], { type: "text/plain" });
423+
body = new TextEncoder().encode(body);
427424
}
428-
429425
// xhr instances automatically filter out unexpected user values
430426
xhr.timeout = details.timeout;
431427
xhr.responseType = details.responseType;

0 commit comments

Comments
 (0)