Optimize IsHex() string helper function

This looks like a silly optimization, but this function gets called for
transaction processing, so returning early when there's no point in even
starting to iterate through a string is just smart coding.
This commit is contained in:
chromatic 2022-10-15 17:36:49 -07:00
parent 763848c56e
commit 5d2a1b2557

View File

@ -58,12 +58,16 @@ signed char HexDigit(char c)
bool IsHex(const string& str)
{
if ((str.size() <= 0) || (str.size()%2 != 0))
return false;
for(std::string::const_iterator it(str.begin()); it != str.end(); ++it)
{
if (HexDigit(*it) < 0)
return false;
}
return (str.size() > 0) && (str.size()%2 == 0);
return true;
}
vector<unsigned char> ParseHex(const char* psz)