mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-29 13:46:31 +00:00
LibJS+LibCrypto: Use a bitwise approach for BigInt's as*IntN methods
This speeds up expressions such as `BigInt.asIntN(0x4000000000000, 1n)` (#3615). And those involving very large bigints.
This commit is contained in:
parent
92d0cd3c7c
commit
12cbefbee7
Notes:
github-actions[bot]
2025-03-20 08:45:14 +00:00
Author: https://github.com/ttrssreal
Commit: 12cbefbee7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3994
Reviewed-by: https://github.com/gmta ✅
9 changed files with 110 additions and 33 deletions
|
@ -22,12 +22,6 @@ describe("errors", () => {
|
|||
BigInt.asUintN(1, "foo");
|
||||
}).toThrowWithMessage(SyntaxError, "Invalid value for BigInt: foo");
|
||||
});
|
||||
|
||||
test("large allocation", () => {
|
||||
expect(() => {
|
||||
BigInt.asUintN(0x4000000000000, 1n);
|
||||
}).toThrowWithMessage(InternalError, "Out of memory");
|
||||
});
|
||||
});
|
||||
|
||||
describe("correct behavior", () => {
|
||||
|
@ -80,4 +74,20 @@ describe("correct behavior", () => {
|
|||
115792089237316195423570861551898784396480861208851440582668460551124006183147n
|
||||
);
|
||||
});
|
||||
|
||||
test("large bit values", () => {
|
||||
const INDEX_MAX = 2 ** 53 - 1;
|
||||
const LAST_8_DIGITS = 10n ** 8n;
|
||||
|
||||
expect(BigInt.asUintN(0x400000000, 1n)).toBe(1n);
|
||||
expect(BigInt.asUintN(0x4000, -1n) % LAST_8_DIGITS).toBe(64066815n);
|
||||
|
||||
expect(BigInt.asUintN(0x400000000, 2n)).toBe(2n);
|
||||
expect(BigInt.asUintN(0x4000, -2n) % LAST_8_DIGITS).toBe(64066814n);
|
||||
|
||||
expect(BigInt.asUintN(INDEX_MAX, 2n)).toBe(2n);
|
||||
expect(() => {
|
||||
BigInt.asUintN(INDEX_MAX, -2n);
|
||||
}).toThrowWithMessage(InternalError, "Out of memory");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue