aboutsummaryrefslogtreecommitdiff
path: root/src/util/strencodings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/strencodings.cpp')
-rw-r--r--src/util/strencodings.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index 4734de3e0b..f514613f0d 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -593,13 +593,14 @@ std::string Capitalize(std::string str)
std::string HexStr(const Span<const uint8_t> s)
{
- std::string rv;
+ std::string rv(s.size() * 2, '\0');
static constexpr char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
- rv.reserve(s.size() * 2);
- for (uint8_t v: s) {
- rv.push_back(hexmap[v >> 4]);
- rv.push_back(hexmap[v & 15]);
+ auto it = rv.begin();
+ for (uint8_t v : s) {
+ *it++ = hexmap[v >> 4];
+ *it++ = hexmap[v & 15];
}
+ assert(it == rv.end());
return rv;
}