зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1599465 - Part 11: Add fast path for BigInt subtraction with uint64 magnitude. r=jwalden
Subtraction doesn't have the same unused malloc memory problem which was present for addition and subtraction, so the relative speed-up when adding a uint64 fast-path is less prominent (only about 10%), but it still seems worthwhile to provide a fast-path, too. Differential Revision: https://phabricator.services.mozilla.com/D54768 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
a3067a0c3b
Коммит
bf1723827b
|
@ -591,6 +591,18 @@ BigInt* BigInt::absoluteSub(JSContext* cx, HandleBigInt x, HandleBigInt y,
|
|||
return resultNegative == x->isNegative() ? x : neg(cx, x);
|
||||
}
|
||||
|
||||
// Fast path for the likely-common case of up to a uint64_t of magnitude.
|
||||
if (x->absFitsInUint64() && y->absFitsInUint64()) {
|
||||
uint64_t lhs = x->uint64FromAbsNonZero();
|
||||
uint64_t rhs = y->uint64FromAbsNonZero();
|
||||
MOZ_ASSERT(lhs > rhs);
|
||||
|
||||
uint64_t res = lhs - rhs;
|
||||
MOZ_ASSERT(res != 0);
|
||||
|
||||
return createFromNonZeroRawUint64(cx, res, resultNegative);
|
||||
}
|
||||
|
||||
RootedBigInt result(
|
||||
cx, createUninitialized(cx, x->digitLength(), resultNegative));
|
||||
if (!result) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче