mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
base_uint cleanups:
* Remove unused and broken reverse iterators * Use charUnHex to reduce code duplication
This commit is contained in:
committed by
Vinnie Falco
parent
386eabb61f
commit
251ce4efbc
@@ -89,13 +89,6 @@ public:
|
|||||||
const_iterator cbegin() const { return data(); }
|
const_iterator cbegin() const { return data(); }
|
||||||
const_iterator cend() const { return data()+bytes; }
|
const_iterator cend() const { return data()+bytes; }
|
||||||
|
|
||||||
reverse_iterator rbegin() { return end(); }
|
|
||||||
reverse_iterator rend() { return begin(); }
|
|
||||||
const_reverse_iterator rbegin() const { return end(); }
|
|
||||||
const_reverse_iterator rend() const { return begin(); }
|
|
||||||
const_reverse_iterator crbegin() const { return cend(); }
|
|
||||||
const_reverse_iterator crend() const { return cbegin(); }
|
|
||||||
|
|
||||||
/** Value hashing function.
|
/** Value hashing function.
|
||||||
The seed prevents crafted inputs from causing degenarate parent containers.
|
The seed prevents crafted inputs from causing degenarate parent containers.
|
||||||
*/
|
*/
|
||||||
@@ -303,42 +296,26 @@ public:
|
|||||||
hash_append (h, a.pn);
|
hash_append (h, a.pn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHexExact (const char* psz)
|
bool SetHexExact (const char* psz)
|
||||||
{
|
{
|
||||||
// must be precisely the correct number of hex digits
|
// must be precisely the correct number of hex digits
|
||||||
static signed char phexdigit[256] =
|
unsigned char* pOut = begin ();
|
||||||
{
|
|
||||||
-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,
|
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
|
|
||||||
|
|
||||||
-1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -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, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -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, -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,
|
|
||||||
};
|
|
||||||
|
|
||||||
char* pOut = reinterpret_cast<char*> (pn);
|
|
||||||
|
|
||||||
for (int i = 0; i < sizeof (pn); ++i)
|
for (int i = 0; i < sizeof (pn); ++i)
|
||||||
{
|
{
|
||||||
*pOut = phexdigit[*psz++] << 4;
|
auto cHigh = charUnHex(*psz++);
|
||||||
*pOut++ |= phexdigit[*psz++];
|
auto cLow = charUnHex(*psz++);
|
||||||
|
|
||||||
|
if (cHigh == -1 || cLow == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*pOut++ = (cHigh << 4) | cLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (*psz == 0);
|
assert (*psz == 0);
|
||||||
assert (pOut == reinterpret_cast<char*> (end ()));
|
assert (pOut == end ());
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow leading whitespace.
|
// Allow leading whitespace.
|
||||||
@@ -355,35 +332,11 @@ public:
|
|||||||
if (!bStrict && psz[0] == '0' && tolower (psz[1]) == 'x')
|
if (!bStrict && psz[0] == '0' && tolower (psz[1]) == 'x')
|
||||||
psz += 2;
|
psz += 2;
|
||||||
|
|
||||||
// hex char to int
|
|
||||||
static 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,
|
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
|
|
||||||
|
|
||||||
-1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -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, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -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, -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,
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned char* pEnd = reinterpret_cast<const unsigned char*> (psz);
|
const unsigned char* pEnd = reinterpret_cast<const unsigned char*> (psz);
|
||||||
const unsigned char* pBegin = pEnd;
|
const unsigned char* pBegin = pEnd;
|
||||||
|
|
||||||
// Find end.
|
// Find end.
|
||||||
while (phexdigit[*pEnd] >= 0)
|
while (charUnHex(*pEnd) != -1)
|
||||||
pEnd++;
|
pEnd++;
|
||||||
|
|
||||||
// Take only last digits of over long string.
|
// Take only last digits of over long string.
|
||||||
@@ -395,15 +348,19 @@ public:
|
|||||||
zero ();
|
zero ();
|
||||||
|
|
||||||
if ((pEnd - pBegin) & 1)
|
if ((pEnd - pBegin) & 1)
|
||||||
*pOut++ = phexdigit[*pBegin++];
|
*pOut++ = charUnHex(*pBegin++);
|
||||||
|
|
||||||
while (pBegin != pEnd)
|
while (pBegin != pEnd)
|
||||||
{
|
{
|
||||||
unsigned char cHigh = phexdigit[*pBegin++] << 4;
|
auto cHigh = charUnHex(*pBegin++);
|
||||||
unsigned char cLow = pBegin == pEnd
|
auto cLow = pBegin == pEnd
|
||||||
? 0
|
? 0
|
||||||
: phexdigit[*pBegin++];
|
: charUnHex(*pBegin++);
|
||||||
*pOut++ = cHigh | cLow;
|
|
||||||
|
if (cHigh == -1 || cLow == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*pOut++ = (cHigh << 4) | cLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !*pEnd;
|
return !*pEnd;
|
||||||
|
|||||||
Reference in New Issue
Block a user