dead code: Remove dead option in HexStr conversion
Problem: - Nothing uses the `fspaces` argument to `HexStr()` besides unit tests. This argument results in extra complexity and a small performance decrease within the function for branch evalulation. Solution: - Remove unused `fspaces` option.
This commit is contained in:
parent
257f750cd9
commit
56f1d28d9b
2 changed files with 5 additions and 47 deletions
|
@ -77,80 +77,40 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
|
|||
HexStr(ParseHex_expected, ParseHex_expected + sizeof(ParseHex_expected)),
|
||||
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_expected, ParseHex_expected + 5, true),
|
||||
"04 67 8a fd b0");
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_expected + sizeof(ParseHex_expected),
|
||||
ParseHex_expected + sizeof(ParseHex_expected)),
|
||||
"");
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_expected + sizeof(ParseHex_expected),
|
||||
ParseHex_expected + sizeof(ParseHex_expected), true),
|
||||
"");
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_expected, ParseHex_expected),
|
||||
"");
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_expected, ParseHex_expected, true),
|
||||
"");
|
||||
|
||||
std::vector<unsigned char> ParseHex_vec(ParseHex_expected, ParseHex_expected + 5);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_vec, true),
|
||||
"04 67 8a fd b0");
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_vec.rbegin(), ParseHex_vec.rend()),
|
||||
"b0fd8a6704"
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_vec.rbegin(), ParseHex_vec.rend(), true),
|
||||
"b0 fd 8a 67 04"
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected),
|
||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
||||
""
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected),
|
||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected), true),
|
||||
""
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 1),
|
||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
||||
"04"
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 1),
|
||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected), true),
|
||||
"04"
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 5),
|
||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
||||
"b0fd8a6704"
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 5),
|
||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected), true),
|
||||
"b0 fd 8a 67 04"
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 65),
|
||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <attributes.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -121,28 +122,25 @@ NODISCARD bool ParseUInt64(const std::string& str, uint64_t *out);
|
|||
NODISCARD bool ParseDouble(const std::string& str, double *out);
|
||||
|
||||
template<typename T>
|
||||
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
|
||||
std::string HexStr(const T itbegin, const T itend)
|
||||
{
|
||||
std::string rv;
|
||||
static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
rv.reserve((itend-itbegin)*3);
|
||||
rv.reserve(std::distance(itbegin, itend) * 2);
|
||||
for(T it = itbegin; it < itend; ++it)
|
||||
{
|
||||
unsigned char val = (unsigned char)(*it);
|
||||
if(fSpaces && it != itbegin)
|
||||
rv.push_back(' ');
|
||||
rv.push_back(hexmap[val>>4]);
|
||||
rv.push_back(hexmap[val&15]);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::string HexStr(const T& vch, bool fSpaces=false)
|
||||
inline std::string HexStr(const T& vch)
|
||||
{
|
||||
return HexStr(vch.begin(), vch.end(), fSpaces);
|
||||
return HexStr(vch.begin(), vch.end());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue