Skip to content

Commit 9a37d21

Browse files
committed
perf: slight improvement in fromBase64 fallback
1 parent cb5e05f commit 9a37d21

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

fallback/base64.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,31 @@ export function fromBase64(str, isURL) {
155155
const codes = nativeEncoder.encode(str)
156156
if (codes.length !== str.length) throw new SyntaxError(E_CHAR) // non-ascii
157157
while (i < mainLength) {
158-
const a = (m[codes[i++]] << 18) | (m[codes[i++]] << 12) | (m[codes[i++]] << 6) | m[codes[i++]]
158+
const c0 = codes[i]
159+
const c1 = codes[i + 1]
160+
const c2 = codes[i + 2]
161+
const c3 = codes[i + 3]
162+
i += 4
163+
const a = (m[c0] << 18) | (m[c1] << 12) | (m[c2] << 6) | m[c3]
159164
if (a < 0) throw new SyntaxError(E_CHAR)
160-
arr[at++] = a >> 16
161-
arr[at++] = (a >> 8) & 0xff
162-
arr[at++] = a & 0xff
165+
arr[at] = a >> 16
166+
arr[at + 1] = (a >> 8) & 0xff
167+
arr[at + 2] = a & 0xff
168+
at += 3
163169
}
164170
} else {
165171
while (i < mainLength) {
166-
const a =
167-
(m[str.charCodeAt(i++)] << 18) |
168-
(m[str.charCodeAt(i++)] << 12) |
169-
(m[str.charCodeAt(i++)] << 6) |
170-
m[str.charCodeAt(i++)]
172+
const c0 = str.charCodeAt(i)
173+
const c1 = str.charCodeAt(i + 1)
174+
const c2 = str.charCodeAt(i + 2)
175+
const c3 = str.charCodeAt(i + 3)
176+
i += 4
177+
const a = (m[c0] << 18) | (m[c1] << 12) | (m[c2] << 6) | m[c3]
171178
if (a < 0) throw new SyntaxError(E_CHAR)
172-
arr[at++] = a >> 16
173-
arr[at++] = (a >> 8) & 0xff
174-
arr[at++] = a & 0xff
179+
arr[at] = a >> 16
180+
arr[at + 1] = (a >> 8) & 0xff
181+
arr[at + 2] = a & 0xff
182+
at += 3
175183
}
176184
}
177185

0 commit comments

Comments
 (0)