Skip to content

Commit 2b99d3a

Browse files
committed
perf: reduce utf8toString fallback tmp arr on small input
1 parent 052feb9 commit 2b99d3a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fallback/utf8.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export function decode(arr, loose, start = 0) {
1010
const end = arr.length
1111
let out = ''
1212
const chunkSize = 0x2_00 // far below MAX_ARGUMENTS_LENGTH in npmjs.com/buffer, we use smaller chunks
13-
const tmp = new Array(chunkSize + 1).fill(0) // need 1 extra slot for last codepoint, which can be 2 charcodes
13+
const tmpSize = Math.min(end - start, chunkSize + 1) // need 1 extra slot for last codepoint, which can be 2 charcodes
14+
const tmp = new Array(tmpSize).fill(0)
1415
let ti = 0
1516

1617
for (let i = start; i < end; i++) {

0 commit comments

Comments
 (0)