Skip to content

Commit 1a70226

Browse files
committed
change bit math instead of using BigInt.asIntN
1 parent 69b7304 commit 1a70226

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/utils/number_utils.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,23 @@ export const NumberUtils: NumberUtils = {
8383

8484
/** Reads a little-endian 64-bit integer from source */
8585
getBigInt64LE(source: Uint8Array, offset: number): bigint {
86-
const lo = NumberUtils.getUint32LE(source, offset);
87-
const hi = NumberUtils.getUint32LE(source, offset + 4);
88-
89-
/*
90-
eslint-disable no-restricted-globals
91-
-- This is allowed since this helper should not be called unless bigint features are enabled
92-
*/
93-
const intermediate = (BigInt(hi) << BigInt(32)) + BigInt(lo);
94-
return BigInt.asIntN(64, intermediate);
95-
/* eslint-enable no-restricted-globals */
86+
// eslint-disable-next-line no-restricted-globals
87+
const hi = BigInt(
88+
source[offset + 4] +
89+
source[offset + 5] * 256 +
90+
source[offset + 6] * 65536 +
91+
(source[offset + 7] << 24)
92+
); // Overflow
93+
94+
// eslint-disable-next-line no-restricted-globals
95+
const lo = BigInt(
96+
source[offset] +
97+
source[offset + 1] * 256 +
98+
source[offset + 2] * 65536 +
99+
source[offset + 3] * 16777216
100+
);
101+
// eslint-disable-next-line no-restricted-globals
102+
return (hi << BigInt(32)) + lo;
96103
},
97104

98105
/** Reads a little-endian 64-bit float from source */

0 commit comments

Comments
 (0)