Skip to content

Commit 1e68411

Browse files
committed
perf: inline assertUint8 check in utf8.js
1 parent ccc8f16 commit 1e68411

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

utf8.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { assertUint8 } from './assert.js'
21
import { typedView } from './array.js'
32
import { nativeDecoder, nativeEncoder, E_STRING, E_STRICT_UNICODE } from './fallback/_utils.js'
43
import * as js from './fallback/utf8.js'
@@ -52,7 +51,7 @@ function encode(str, loose = false) {
5251
}
5352

5453
function decode(arr, loose = false) {
55-
assertUint8(arr)
54+
if (!(arr instanceof Uint8Array)) throw new TypeError('Expected an Uint8Array')
5655
if (arr.byteLength === 0) return ''
5756
if (nativeDecoder || !js.decodeFast) {
5857
return loose ? decoderLoose.decode(arr) : decoderFatal.decode(arr) // Node.js and browsers

utf8.node.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { assertUint8 } from './assert.js'
21
import { typedView } from './array.js'
32
import { E_STRING, E_STRICT_UNICODE } from './fallback/_utils.js'
43
import { E_STRICT } from './fallback/utf8.js'
@@ -40,7 +39,7 @@ function encode(str, loose = false) {
4039
}
4140

4241
function decode(arr, loose = false) {
43-
assertUint8(arr)
42+
if (!(arr instanceof Uint8Array)) throw new TypeError('Expected an Uint8Array')
4443
const byteLength = arr.byteLength
4544
if (byteLength === 0) return ''
4645
if (byteLength > 0x6_00 && !(isDeno && loose) && isAscii(arr)) {

0 commit comments

Comments
 (0)