Skip to content

Commit fa5a081

Browse files
committed
doc: mention that internal encodeAscii is aligned
1 parent 951b0b7 commit fa5a081

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

fallback/hex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function fromHex(str) {
7373
}
7474
}
7575

76-
const codes = encodeAscii(str, E_HEX)
76+
const codes = encodeAscii(str, E_HEX) // aligned
7777
const codes16 = new Uint16Array(codes.buffer, codes.byteOffset, codes.byteLength / 2)
7878
let i = 0
7979
for (const last3 = length - 3; i < last3; i += 4) {

fallback/latin1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const encodeAscii = useEncodeInto
140140
: nativeBuffer
141141
? (str, ERR) => {
142142
// TextEncoder is slow on Node.js 24 / 25 (was ok on 22)
143+
// Node.js Buffer.from always returns 8-byte aligned allocations, this is safe for e.g. conversion to Uint32Array
143144
const codes = nativeBuffer.from(str, 'utf8') // ascii/latin1 coerces, we need to check
144145
if (codes.length !== str.length) throw new SyntaxError(ERR) // non-ascii
145146
return new Uint8Array(codes.buffer, codes.byteOffset, codes.byteLength)

0 commit comments

Comments
 (0)