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:
André Bargull 2019-12-02 17:37:08 +00:00
Родитель a3067a0c3b
Коммит bf1723827b
1 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -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) {