LibCrypto: Preallocate 128 words of space for UnsignedBigInteger

This shaves off 1 second of runtime
This commit is contained in:
AnotherTest 2020-04-20 21:01:01 +04:30 committed by Andreas Kling
parent 2247036acf
commit 8d20a526e5
Notes: sideshowbarker 2024-07-19 07:05:02 +09:00

View file

@ -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<u32, STARTING_WORD_SIZE>&& words)
: m_words(move(words))
: m_words(words)
{
}
@ -59,7 +60,7 @@ public:
return export_data(buffer);
}
const AK::Vector<u32>& words() const { return m_words; }
const AK::Vector<u32, STARTING_WORD_SIZE>& 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<u32> m_words;
AK::Vector<u32, STARTING_WORD_SIZE> m_words;
// Used to indicate a negative result, or a result of an invalid operation
bool m_is_invalid { false };