Skip to content

Commit

Permalink
Speed-up byte array testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Nov 8, 2024
1 parent d9371e7 commit 03221c8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/_assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ function bool(b: boolean) {
// copied from utils
export function isBytes(a: unknown): a is Uint8Array {
return (
a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')
a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array')
);
}

Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { bytes as abytes } 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')
a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array')
);
}

Expand Down

0 comments on commit 03221c8

Please sign in to comment.