mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
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>
This commit is contained in:
10
src/util.cpp
10
src/util.cpp
@@ -455,7 +455,7 @@ bool ParseMoney(const char* pszIn, int64& nRet)
|
||||
}
|
||||
|
||||
|
||||
static const signed char phexdigit[256] =
|
||||
const signed char p_util_hexdigit[256] =
|
||||
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
@@ -475,9 +475,9 @@ static const signed char phexdigit[256] =
|
||||
|
||||
bool IsHex(const string& str)
|
||||
{
|
||||
BOOST_FOREACH(unsigned char c, str)
|
||||
BOOST_FOREACH(char c, str)
|
||||
{
|
||||
if (phexdigit[c] < 0)
|
||||
if (HexDigit(c) < 0)
|
||||
return false;
|
||||
}
|
||||
return (str.size() > 0) && (str.size()%2 == 0);
|
||||
@@ -491,11 +491,11 @@ vector<unsigned char> ParseHex(const char* psz)
|
||||
{
|
||||
while (isspace(*psz))
|
||||
psz++;
|
||||
signed char c = phexdigit[(unsigned char)*psz++];
|
||||
signed char c = HexDigit(*psz++);
|
||||
if (c == (signed char)-1)
|
||||
break;
|
||||
unsigned char n = (c << 4);
|
||||
c = phexdigit[(unsigned char)*psz++];
|
||||
c = HexDigit(*psz++);
|
||||
if (c == (signed char)-1)
|
||||
break;
|
||||
n |= c;
|
||||
|
||||
Reference in New Issue
Block a user