diff options
author | Olivier Langlois <olivier@olivierlanglois.net> | 2013-10-10 12:35:51 -0400 |
---|---|---|
committer | Olivier Langlois <olivier@olivierlanglois.net> | 2013-10-27 23:04:52 -0400 |
commit | f171ec0c7d084b6bb163d1466edd814cf4dcbc93 (patch) | |
tree | cb0708afc624eeb68a0b0b5db0aca19e9cc58984 /src/uint256.h | |
parent | 15b48ab03612952b355cdd411cc541668d147bfb (diff) |
Make util phexdigit array reusable
class template base_uint had its own private lookup table.
This is saving 256 bytes per instantiation.
The result is not spectacular as bitcoin-qt has only shrinked of
about 1Kb but it is still valid improvement.
Also, I have replaced a for loop with a memset() call.
Made CBigNum::SetHex() use the new HexDigit() function.
Signed-off-by: Olivier Langlois <olivier@olivierlanglois.net>
Diffstat (limited to 'src/uint256.h')
-rw-r--r-- | src/uint256.h | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/uint256.h b/src/uint256.h index 45ab8abb5e..562426a0d8 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -14,7 +14,12 @@ typedef long long int64; typedef unsigned long long uint64; +extern const signed char p_util_hexdigit[256]; // defined in util.cpp +inline signed char HexDigit(char c) +{ + return p_util_hexdigit[(unsigned char)c]; +} inline int Testuint256AdHoc(std::vector<std::string> vArg); @@ -305,8 +310,7 @@ public: void SetHex(const char* psz) { - for (int i = 0; i < WIDTH; i++) - pn[i] = 0; + memset(pn,0,sizeof(pn)); // skip leading spaces while (isspace(*psz)) @@ -317,19 +321,18 @@ public: psz += 2; // hex string to uint - static const unsigned char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 }; const char* pbegin = psz; - while (phexdigit[(unsigned char)*psz] || *psz == '0') + while (::HexDigit(*psz) != -1) psz++; psz--; unsigned char* p1 = (unsigned char*)pn; unsigned char* pend = p1 + WIDTH * 4; while (psz >= pbegin && p1 < pend) { - *p1 = phexdigit[(unsigned char)*psz--]; + *p1 = ::HexDigit(*psz--); if (psz >= pbegin) { - *p1 |= (phexdigit[(unsigned char)*psz--] << 4); + *p1 |= ((unsigned char)::HexDigit(*psz--) << 4); p1++; } } |