mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:37:45 +00:00
LibCrypto: Cache the "trimmed length" of UnsignedBigIntegers
This avoids repeated traversals of the underlying words and gives a 30% speed-up on "test-crypto -t pk" :^)
This commit is contained in:
parent
57f68ac5d7
commit
444b6c8407
2 changed files with 24 additions and 9 deletions
|
@ -52,8 +52,8 @@ public:
|
|||
static UnsignedBigInteger import_data(const AK::StringView& data) { return import_data((const u8*)data.characters_without_null_termination(), data.length()); }
|
||||
static UnsignedBigInteger import_data(const u8* ptr, size_t length);
|
||||
|
||||
size_t export_data(AK::ByteBuffer& data);
|
||||
size_t export_data(const u8* ptr, size_t length)
|
||||
size_t export_data(AK::ByteBuffer& data) const;
|
||||
size_t export_data(const u8* ptr, size_t length) const
|
||||
{
|
||||
auto buffer = ByteBuffer::wrap(ptr, length);
|
||||
return export_data(buffer);
|
||||
|
@ -67,7 +67,12 @@ public:
|
|||
void set_to_0();
|
||||
void set_to(u32 other);
|
||||
void set_to(const UnsignedBigInteger& other);
|
||||
void invalidate() { m_is_invalid = true; }
|
||||
|
||||
void invalidate()
|
||||
{
|
||||
m_is_invalid = true;
|
||||
m_cached_trimmed_length = {};
|
||||
}
|
||||
|
||||
bool is_invalid() const { return m_is_invalid; }
|
||||
|
||||
|
@ -103,6 +108,8 @@ private:
|
|||
|
||||
// Used to indicate a negative result, or a result of an invalid operation
|
||||
bool m_is_invalid { false };
|
||||
|
||||
mutable Optional<size_t> m_cached_trimmed_length;
|
||||
};
|
||||
|
||||
struct UnsignedDivisionResult {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue