From 9c9813c3122c0908f89f0a75714f1c42defe36bc Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 9 Jul 2021 11:50:42 +0100 Subject: [PATCH] LibJS: Replace useless use of SignedBigInteger::create_from() with ctor create_from() casts the value to a 64 bit integer and then creates two words from it, which is not necessary if we only pass values to it that fit into a single word (32 bit integer). Also make them use UnsignedBigInteger as the previously missing SBI divided_by() overload is now implemented. --- .../Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index 7633b5d9bb..3ade1273de 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include #include @@ -58,7 +58,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_seconds_getter) auto& ns = instant->nanoseconds(); // 4. Let s be RoundTowardsZero(ℝ(ns) / 10^9). - auto [s, _] = ns.big_integer().divided_by(Crypto::SignedBigInteger::create_from(1'000'000'000)); + auto [s, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000'000 }); // 5. Return 𝔽(s). return Value((double)s.to_base(10).to_int().value()); @@ -77,7 +77,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_milliseconds_getter) auto& ns = instant->nanoseconds(); // 4. Let ms be RoundTowardsZero(ℝ(ns) / 10^6). - auto [ms, _] = ns.big_integer().divided_by(Crypto::SignedBigInteger::create_from(1'000'000)); + auto [ms, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000 }); // 5. Return 𝔽(ms). return Value((double)ms.to_base(10).to_int().value()); @@ -96,7 +96,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_microseconds_getter) auto& ns = instant->nanoseconds(); // 4. Let µs be RoundTowardsZero(ℝ(ns) / 10^3). - auto [us, _] = ns.big_integer().divided_by(Crypto::SignedBigInteger::create_from(1'000)); + auto [us, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000 }); // 5. Return ℤ(µs). return js_bigint(vm.heap(), move(us));