Skip to content

Commit 952688e

Browse files
committed
refactor: earlier check for empty input in encoding.js
1 parent e2f6e7c commit 952688e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

fallback/encoding.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ export class TextDecoder {
6262
if (typeof options !== 'object') throw new TypeError(E_OPTIONS)
6363
const stream = Boolean(options.stream)
6464
let u = input === undefined ? new Uint8Array() : fromSource(input)
65+
const empty = u.length === 0 // also can't be streaming after next line
66+
if (empty && stream) return '' // no state change
6567

6668
if (this.#unicode) {
6769
let prefix
6870
if (this.#chunk) {
69-
if (u.length === 0) {
70-
if (stream) return '' // no change
71+
if (empty) {
7172
u = this.#chunk // process as final chunk to handle errors and state changes
7273
} else if (u.length < 3) {
7374
// No reason to bruteforce offsets, also it's possible this doesn't yet end the sequence
@@ -96,8 +97,8 @@ export class TextDecoder {
9697
}
9798

9899
this.#chunk = null
99-
} else if (u.byteLength === 0) {
100-
if (!stream) this.#canBOM = !this.ignoreBOM
100+
} else if (empty) {
101+
this.#canBOM = !this.ignoreBOM // not streaming
101102
return ''
102103
}
103104

0 commit comments

Comments
 (0)