LibCrypto: Preallocate 128 words of space for UnsignedBigInteger
This shaves off 1 second of runtime
This commit is contained in:
parent
2247036acf
commit
8d20a526e5
Notes:
sideshowbarker
2024-07-19 07:05:02 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/8d20a526e57 Pull-request: https://github.com/SerenityOS/serenity/pull/1661 Reviewed-by: https://github.com/Dexesttp Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/itamar8910
1 changed files with 4 additions and 3 deletions
|
@ -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 };
|
||||
|
|
Loading…
Add table
Reference in a new issue