1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

LibJS: Replace comparisons of "0"_bigint with SignedBigInteger::is_zero

This just avoids creating UnsignedBigInteger's underlying vector.
This commit is contained in:
Timothy Flynn 2022-07-16 12:43:23 -04:00 committed by Linus Groh
parent 440d185666
commit a712c7b5e1
4 changed files with 4 additions and 4 deletions

View file

@ -183,7 +183,7 @@ auto modulo(T x, U y) requires(IsArithmetic<T>, IsArithmetic<U>)
auto modulo(Crypto::BigInteger auto const& x, Crypto::BigInteger auto const& y)
{
VERIFY(y != "0"_bigint);
VERIFY(!y.is_zero());
auto result = x.divided_by(y).remainder;
if (result.is_negative())
result = result.plus(y);

View file

@ -446,7 +446,7 @@ static ALWAYS_INLINE bool is_zero(Value number)
{
if (number.is_number())
return number.as_double() == 0.0;
return number.as_bigint().big_integer() == Crypto::SignedBigInteger::create_from(0);
return number.as_bigint().big_integer().is_zero();
}
static ALWAYS_INLINE bool is_greater_than(Value number, i64 rhs)

View file

@ -1530,7 +1530,7 @@ ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(GlobalObject& glo
i32 direction;
// 3. If timeRemainderNs = 0, let direction be 0.
if (time_remainder_ns == "0"_bigint)
if (time_remainder_ns.is_zero())
direction = 0;
// 4. Else if timeRemainderNs < 0, let direction be -1.
else if (time_remainder_ns.is_negative())

View file

@ -452,7 +452,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
auto day_length_ns = ns_per_day_bigint;
// 2. If nanoseconds = 0, then
if (nanoseconds == "0"_bigint) {
if (nanoseconds.is_zero()) {
// a. Return the Record { [[Days]]: 0, [[Nanoseconds]]: 0, [[DayLength]]: dayLengthNs }.
return NanosecondsToDaysResult { .days = 0, .nanoseconds = "0"_sbigint, .day_length = day_length_ns.to_double() };
}