Skip to content

Commit f298ad0

Browse files
committed
perf: label more helpers as pure
1 parent 6160cc0 commit f298ad0

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

fallback/_utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export const E_STRICT_UNICODE = 'Input is not well-formed Unicode'
1010
let isNative = (x) => x && (haveNativeBuffer || `${x}`.includes('[native code]'))
1111
if (!haveNativeBuffer && isNative(() => {})) isNative = () => false // e.g. XS, we don't want false positives
1212

13-
export const nativeEncoder = isNative(TextEncoder) ? new TextEncoder() : null
14-
export const nativeDecoder = isNative(TextDecoder)
15-
? new TextDecoder('utf-8', { ignoreBOM: true })
16-
: null
13+
export const nativeEncoder = /* @__PURE__ */ (() =>
14+
isNative(TextEncoder) ? new TextEncoder() : null)()
15+
export const nativeDecoder = /* @__PURE__ */ (() =>
16+
isNative(TextDecoder) ? new TextDecoder('utf-8', { ignoreBOM: true }) : null)()
1717

1818
// Actually windows-1252, compatible with ascii and latin1 decoding
1919
// Beware that on non-latin1, i.e. on windows-1252, this is broken in ~all Node.js versions released

fallback/latin1.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
skipWeb,
1010
} from './_utils.js'
1111

12-
const { atob } = globalThis
13-
const { toBase64: web64 } = Uint8Array.prototype
12+
const atob = /* @__PURE__ */ (() => globalThis.atob)()
13+
const web64 = /* @__PURE__ */ (() => Uint8Array.prototype.toBase64)()
1414

1515
// See http://stackoverflow.com/a/22747272/680742, which says that lowest limit is in Chrome, with 0xffff args
1616
// On Hermes, actual max is 0x20_000 minus current stack depth, 1/16 of that should be safe
@@ -147,7 +147,7 @@ export function encodeAsciiPrefix(x, s) {
147147
export const encodeLatin1 = (str) => encodeCharcodes(str, new Uint8Array(str.length))
148148

149149
// Expects nativeEncoder to be present
150-
const useEncodeInto = isHermes && nativeEncoder?.encodeInto
150+
const useEncodeInto = /* @__PURE__ */ (() => isHermes && nativeEncoder?.encodeInto)()
151151
export const encodeAscii = useEncodeInto
152152
? (str, ERR) => {
153153
// Much faster in Hermes

0 commit comments

Comments
 (0)