diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-11-04 05:55:37 -0800 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-11-04 05:55:37 -0800 |
commit | bac72640ee4fbf32c639901229dcd714defa1baa (patch) | |
tree | 78ea27076d3d41c62d7ad873335c34a80f8343b9 /src/uint256.h | |
parent | 97f844dd95c54b0fe2f2a1bb006c74ff544ff125 (diff) | |
parent | f171ec0c7d084b6bb163d1466edd814cf4dcbc93 (diff) |
Merge pull request #3076 from lano1106/uint256_util
Make util phexdigit array reusable
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 79404f1b16..b5a4950eaa 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++; } } |