From 8d20a526e57d9551acfded39b34761bdea7eca0f Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 20 Apr 2020 21:01:01 +0430 Subject: [PATCH] LibCrypto: Preallocate 128 words of space for UnsignedBigInteger This shaves off 1 second of runtime --- Libraries/LibCrypto/BigInt/UnsignedBigInteger.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h index dbecbf0735..6238ccef6a 100644 --- a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h +++ b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h @@ -34,13 +34,14 @@ namespace Crypto { struct UnsignedDivisionResult; +constexpr size_t STARTING_WORD_SIZE = 128; class UnsignedBigInteger { public: UnsignedBigInteger(u32 x) { m_words.append(x); } explicit UnsignedBigInteger(AK::Vector&& words) - : m_words(move(words)) + : m_words(words) { } @@ -59,7 +60,7 @@ public: return export_data(buffer); } - const AK::Vector& words() const { return m_words; } + const AK::Vector& words() const { return m_words; } UnsignedBigInteger add(const UnsignedBigInteger& other) const; UnsignedBigInteger sub(const UnsignedBigInteger& other) const; @@ -89,7 +90,7 @@ private: u32 shift_left_get_one_word(const size_t num_bits, const size_t result_word_index) const; static constexpr size_t BITS_IN_WORD = 32; - AK::Vector m_words; + AK::Vector m_words; // Used to indicate a negative result, or a result of an invalid operation bool m_is_invalid { false };