From c9321b4f009a4e8a143d55e30ba5e0a4718785ff Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Wed, 29 Apr 2020 22:35:54 +0430 Subject: [PATCH] LibCrypto: Make UnsignedBigInteger as fast as architecturally possible This commit attempts to make UnsignedBigInteger as fast as possible without changing the underlaying architecture. This effort involves - Preallocating space for vector operations - Avoiding calls to computationally expensive functions - Inlining or flattening functions (sensibly) --- .../LibCrypto/BigInt/UnsignedBigInteger.cpp | 23 +++++++++++-------- .../LibCrypto/BigInt/UnsignedBigInteger.h | 6 ++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp index 88de7d4ddc..29bc5eb7b5 100644 --- a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp +++ b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp @@ -90,7 +90,7 @@ UnsignedBigInteger UnsignedBigInteger::plus(const UnsignedBigInteger& other) con word_addition_result++; } carry = carry_out; - result.m_words.append(word_addition_result); + result.m_words.unchecked_append(word_addition_result); } for (size_t i = shorter->length(); i < longer->length(); ++i) { @@ -100,10 +100,10 @@ UnsignedBigInteger UnsignedBigInteger::plus(const UnsignedBigInteger& other) con if (word_addition_result < longer->m_words[i]) { carry = 1; } - result.m_words.append(word_addition_result); + result.m_words.unchecked_append(word_addition_result); } if (carry) { - result.m_words.append(carry); + result.m_words.unchecked_append(carry); } return result; } @@ -149,7 +149,7 @@ UnsignedBigInteger UnsignedBigInteger::minus(const UnsignedBigInteger& other) co * So to multiple x*y, we go over each '1' bit in x (say the i'th bit), * and add y< m_words;