From a712c7b5e171f6b57ef7e02be2b0d41a725464c3 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 16 Jul 2022 12:43:23 -0400 Subject: [PATCH] LibJS: Replace comparisons of "0"_bigint with SignedBigInteger::is_zero This just avoids creating UnsignedBigInteger's underlying vector. --- Userland/Libraries/LibJS/Runtime/AbstractOperations.h | 2 +- Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index edfd8406ec..3a0162fbb7 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -183,7 +183,7 @@ auto modulo(T x, U y) requires(IsArithmetic, IsArithmetic) 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); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index ddeb23d7f6..53d757f34a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -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) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp index 896aecd397..6dff4d5e64 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp @@ -1530,7 +1530,7 @@ ThrowCompletionOr 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()) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index c86f76c7e8..ae4fdc5bd5 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp @@ -452,7 +452,7 @@ ThrowCompletionOr 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() }; }