Skip to content

Commit 0e9fca2

Browse files
committed
reuse TextDecoder
1 parent 31470a6 commit 0e9fca2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ function byteLength (string, encoding) {
478478
}
479479
Buffer.byteLength = byteLength
480480

481+
let decoderUTF8 = new TextDecoder("utf8");
482+
481483
function slowToString (encoding, start, end) {
482484
let loweredCase = false
483485

@@ -522,7 +524,7 @@ function slowToString (encoding, start, end) {
522524

523525
case 'utf8':
524526
case 'utf-8':
525-
return new TextDecoder(encoding).decode(this.slice(start, end))
527+
return decoderUTF8.decode(this.slice(start, end))
526528

527529
case 'ascii':
528530
return asciiSlice(this, start, end)

0 commit comments

Comments
 (0)