Skip to content

Commit

Permalink
utils: fix big performance issue due to re-export
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Mar 14, 2024
1 parent 89dcae6 commit 396da92
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
// Makes the utils un-importable in browsers without a bundler.
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
import { crypto } from '@noble/hashes/crypto';
import { isBytes, bytes as abytes } from './_assert.js';
import { bytes as abytes } from './_assert.js';
// export { isBytes } from './_assert.js';
// We can't reuse isBytes from _assert, because somehow this causes huge perf issues
export function isBytes(a: unknown): a is Uint8Array {
return (
a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')
);
}

// prettier-ignore
export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |
Expand Down Expand Up @@ -38,8 +46,6 @@ export const byteSwap = (word: number) =>
// Conditionally byte swap if on a big-endian platform
export const byteSwapIfBE = isLE ? (n: number) => n : (n: number) => byteSwap(n);

export { isBytes };

// In place byte swap for Uint32Array
export function byteSwap32(arr: Uint32Array) {
for (let i = 0; i < arr.length; i++) {
Expand Down

0 comments on commit 396da92

Please sign in to comment.