Skip to content

Commit 951b0b7

Browse files
committed
chore: also prevent pooled TypedArrays in non-shipped /utf32.js
1 parent e20c47f commit 951b0b7

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

fallback/utf32.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function decode(u32) {
5858
}
5959

6060
// Only defined on valid input
61+
// Returns non-pooled exact view
6162
// TODO: add fast path for prefix without high bits
6263
export function utf16to32(u16) {
6364
const length = u16.length
@@ -72,12 +73,13 @@ export function utf16to32(u16) {
7273
}
7374
}
7475

75-
return i === length ? u32 : u32.subarray(0, i)
76+
return i === length ? u32 : u32.slice(0, i)
7677
}
7778

7879
// Only defined on valid input
80+
// Can return a subarray
7981
// TODO: add fast path for prefix without high bits?
80-
export function utf32to16(u32) {
82+
export function utf32to16view(u32) {
8183
const length = u32.length
8284
const u16 = new Uint16Array(length * 2)
8385
let i = 0

utf32.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function decode(input, loose = false, format = 'uint32') {
5757
if (isHermes) return js.decode(u32, loose)
5858

5959
// Significantly faster on Node.js, Chromium, v8, WebKit
60-
const u16 = js.utf32to16(u32)
60+
const u16 = js.utf32to16view(u32)
6161
return loose ? utf16.utf16toStringLoose(u16) : utf16.utf16toString(u16)
6262
}
6363

0 commit comments

Comments
 (0)