Browse Source

HexStr: don't build a vector<char> first

Also const correctness for lookup tables in hex functions throughout the code.
miguelfreitas
Wladimir J. van der Laan 12 years ago
parent
commit
ac4e7f6269
  1. 2
      src/bignum.h
  2. 2
      src/uint256.h
  3. 2
      src/util.cpp
  4. 6
      src/util.h

2
src/bignum.h

@ -305,7 +305,7 @@ public:
psz++; psz++;
// hex string to bignum // hex string to bignum
static signed 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 }; static const signed 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 };
*this = 0; *this = 0;
while (isxdigit(*psz)) while (isxdigit(*psz))
{ {

2
src/uint256.h

@ -306,7 +306,7 @@ public:
psz += 2; psz += 2;
// hex string to uint // hex string to uint
static 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 }; 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; const char* pbegin = psz;
while (phexdigit[(unsigned char)*psz] || *psz == '0') while (phexdigit[(unsigned char)*psz] || *psz == '0')
psz++; psz++;

2
src/util.cpp

@ -424,7 +424,7 @@ bool ParseMoney(const char* pszIn, int64& nRet)
} }
static signed char phexdigit[256] = static const signed char phexdigit[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, -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,

6
src/util.h

@ -256,8 +256,8 @@ inline int64 abs64(int64 n)
template<typename T> template<typename T>
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false) std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
{ {
std::vector<char> rv; std::string rv;
static char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7', static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
rv.reserve((itend-itbegin)*3); rv.reserve((itend-itbegin)*3);
for(T it = itbegin; it < itend; ++it) for(T it = itbegin; it < itend; ++it)
@ -269,7 +269,7 @@ std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
rv.push_back(hexmap[val&15]); rv.push_back(hexmap[val&15]);
} }
return std::string(rv.begin(), rv.end()); return rv;
} }
inline std::string HexStr(const std::vector<unsigned char>& vch, bool fSpaces=false) inline std::string HexStr(const std::vector<unsigned char>& vch, bool fSpaces=false)

Loading…
Cancel
Save