Skip to content

Commit ba38d5e

Browse files
committed
feat: latin1fromString never returns pooled Uint8Arrays
1 parent d8cd85c commit ba38d5e

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

fallback/encoding.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,5 @@ export function isomorphicDecode(input) {
367367
}
368368

369369
export function isomorphicEncode(str) {
370-
const res = latin1fromString(str)
371-
// match new Uint8Array, which is non-pooled
372-
return res.byteOffset === 0 && res.length === res.buffer.byteLength ? res : res.slice(0)
370+
return latin1fromString(str)
373371
}

single-byte.node.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ function encode(s, m) {
9090
export function latin1fromString(s) {
9191
if (typeof s !== 'string') throw new TypeError(E_STRING)
9292
if (NON_LATIN.test(s)) throw new TypeError(E_STRICT)
93-
const b = Buffer.from(s, 'latin1')
94-
return new Uint8Array(b.buffer, b.byteOffset, b.byteLength)
93+
const ab = new ArrayBuffer(s.length)
94+
Buffer.from(ab).latin1Write(s)
95+
return new Uint8Array(ab)
9596
}
9697

9798
export function createSinglebyteEncoder(encoding, { mode = 'fatal' } = {}) {

0 commit comments

Comments
 (0)