diff options
author | Jack Lloyd <[email protected]> | 2018-02-23 08:11:52 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-02-23 08:11:52 -0500 |
commit | 6fbe80af97d6788f82ae3e570e7279801ca6d9bf (patch) | |
tree | 38a8598ad7ba7f4a08ba1338682b7d49128b2102 /src/lib | |
parent | e8bd6207f9de23c5a2709b9a8ad45cb5cf71beb3 (diff) |
Minor optimizations in BigInt memory handling
Makes 4-6% difference for ECDSA
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/math/bigint/big_ops2.cpp | 4 | ||||
-rw-r--r-- | src/lib/math/bigint/bigint.cpp | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/lib/math/bigint/big_ops2.cpp b/src/lib/math/bigint/big_ops2.cpp index c203f363a..639d87ceb 100644 --- a/src/lib/math/bigint/big_ops2.cpp +++ b/src/lib/math/bigint/big_ops2.cpp @@ -21,7 +21,9 @@ BigInt& BigInt::operator+=(const BigInt& y) const size_t x_sw = sig_words(), y_sw = y.sig_words(); const size_t reg_size = std::max(x_sw, y_sw) + 1; - grow_to(reg_size); + + if(m_reg.size() < reg_size) + grow_to(reg_size); if(sign() == y.sign()) bigint_add2(mutable_data(), reg_size - 1, y.data(), y_sw); diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp index b63bd9be8..e5f8974d5 100644 --- a/src/lib/math/bigint/bigint.cpp +++ b/src/lib/math/bigint/bigint.cpp @@ -23,7 +23,7 @@ BigInt::BigInt(uint64_t n) const size_t limbs_needed = sizeof(uint64_t) / sizeof(word); - m_reg.resize(4*limbs_needed); + m_reg.resize(limbs_needed); for(size_t i = 0; i != limbs_needed; ++i) m_reg[i] = ((n >> (i*MP_WORD_BITS)) & MP_WORD_MASK); } |