mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
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.
This commit is contained in:
parent
a216ea4c8d
commit
9c9813c312
Notes:
sideshowbarker
2024-07-18 10:00:41 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/9c9813c3122 Pull-request: https://github.com/SerenityOS/serenity/pull/8580
1 changed files with 4 additions and 4 deletions
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
||||
#include <LibCrypto/BigInt/UnsignedBigInteger.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Temporal/Instant.h>
|
||||
#include <LibJS/Runtime/Temporal/InstantPrototype.h>
|
||||
|
@ -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<i64>().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<i64>().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));
|
||||
|
|
Loading…
Reference in a new issue