Skip to content

Commit b0772e4

Browse files
committed
perf: another 10% improvement in Hermes fromHex
1 parent 59d7e40 commit b0772e4

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

fallback/hex.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export function fromHex(str) {
8888

8989
const length = str.length / 2 // this helps Hermes in loops
9090
const arr = new Uint8Array(length)
91-
let j = 0
9291

9392
// Native encoder path is beneficial even for small arrays in Hermes
9493
if (nativeEncoder) {
@@ -120,11 +119,11 @@ export function fromHex(str) {
120119

121120
const codes16 = new Uint16Array(codes.buffer, codes.byteOffset, codes.byteLength / 2)
122121
let i = 0
123-
for (const last3 = length - 3; i < last3; ) {
124-
const ai = codes16[j++]
125-
const bi = codes16[j++]
126-
const ci = codes16[j++]
127-
const di = codes16[j++]
122+
for (const last3 = length - 3; i < last3; i += 4) {
123+
const ai = codes16[i]
124+
const bi = codes16[i + 1]
125+
const ci = codes16[i + 2]
126+
const di = codes16[i + 3]
128127
const a = dehexArray[ai]
129128
const b = dehexArray[bi]
130129
const c = dehexArray[ci]
@@ -133,14 +132,14 @@ export function fromHex(str) {
133132
throw new SyntaxError(E_HEX)
134133
}
135134

136-
arr[i++] = a
137-
arr[i++] = b
138-
arr[i++] = c
139-
arr[i++] = d
135+
arr[i] = a
136+
arr[i + 1] = b
137+
arr[i + 2] = c
138+
arr[i + 3] = d
140139
}
141140

142141
while (i < length) {
143-
const ai = codes16[j++]
142+
const ai = codes16[i]
144143
const a = dehexArray[ai]
145144
if (!a && ai !== _00) throw new SyntaxError(E_HEX)
146145
arr[i++] = a
@@ -156,6 +155,7 @@ export function fromHex(str) {
156155
}
157156
}
158157

158+
let j = 0
159159
for (let i = 0; i < length; i++) {
160160
const a = str.charCodeAt(j++)
161161
const b = str.charCodeAt(j++)

0 commit comments

Comments
 (0)