Merge #15573: dead code: Remove dead option in HexStr conversion
56f1d28d9b
dead code: Remove dead option in HexStr conversion (Lenny Maiorani)
Pull request description:
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.
Solution:
- Remove unused `fspaces` option.
- Remove associated unit tests.
Tree-SHA512: 33d00ce354bbc62a77232fa301cdef0a9ed2c5a09e792bc40e9620c2f2f88636e322a38c76b81d10d12a1768dd1b3b2b9cf180f7e33daef9b4f27afed68ccf70
This commit is contained in:
commit
c3b1cb958f
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)),
|
HexStr(ParseHex_expected, ParseHex_expected + sizeof(ParseHex_expected)),
|
||||||
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");
|
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(
|
|
||||||
HexStr(ParseHex_expected, ParseHex_expected + 5, true),
|
|
||||||
"04 67 8a fd b0");
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(
|
BOOST_CHECK_EQUAL(
|
||||||
HexStr(ParseHex_expected + sizeof(ParseHex_expected),
|
HexStr(ParseHex_expected + sizeof(ParseHex_expected),
|
||||||
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(
|
BOOST_CHECK_EQUAL(
|
||||||
HexStr(ParseHex_expected, ParseHex_expected),
|
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);
|
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(
|
BOOST_CHECK_EQUAL(
|
||||||
HexStr(ParseHex_vec.rbegin(), ParseHex_vec.rend()),
|
HexStr(ParseHex_vec.rbegin(), ParseHex_vec.rend()),
|
||||||
"b0fd8a6704"
|
"b0fd8a6704"
|
||||||
);
|
);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(
|
|
||||||
HexStr(ParseHex_vec.rbegin(), ParseHex_vec.rend(), true),
|
|
||||||
"b0 fd 8a 67 04"
|
|
||||||
);
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(
|
BOOST_CHECK_EQUAL(
|
||||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected),
|
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected),
|
||||||
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(
|
BOOST_CHECK_EQUAL(
|
||||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 1),
|
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 1),
|
||||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
||||||
"04"
|
"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(
|
BOOST_CHECK_EQUAL(
|
||||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 5),
|
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 5),
|
||||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
||||||
"b0fd8a6704"
|
"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(
|
BOOST_CHECK_EQUAL(
|
||||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 65),
|
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 65),
|
||||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
std::reverse_iterator<const uint8_t *>(ParseHex_expected)),
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <attributes.h>
|
#include <attributes.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <iterator>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#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);
|
NODISCARD bool ParseDouble(const std::string& str, double *out);
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::string rv;
|
std::string rv;
|
||||||
static const 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(std::distance(itbegin, itend) * 2);
|
||||||
for(T it = itbegin; it < itend; ++it)
|
for(T it = itbegin; it < itend; ++it)
|
||||||
{
|
{
|
||||||
unsigned char val = (unsigned char)(*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>>4]);
|
||||||
rv.push_back(hexmap[val&15]);
|
rv.push_back(hexmap[val&15]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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