Skip to content

Commit fe74ddb

Browse files
committed
deps: try different HexEncode impl
1 parent 8c57908 commit fe74ddb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

deps/nbytes/src/nbytes.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,20 @@ const int8_t unhex_table[256] = {
157157
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158158
-1, -1, -1, -1, -1, -1, -1, -1, -1};
159159

160+
inline char nibble(uint8_t x) {
161+
return x + '0' + ((x > 9) * 39);
162+
}
163+
160164
size_t HexEncode(const char *src, size_t slen, char *dst, size_t dlen) {
161165
// We know how much we'll write, just make sure that there's space.
162166
NBYTES_ASSERT_TRUE(dlen >= MultiplyWithOverflowCheck<size_t>(slen, 2u) &&
163167
"not enough space provided for hex encode");
164168

165169
dlen = slen * 2;
166170
for (size_t i = 0, k = 0; k < dlen; i += 1, k += 2) {
167-
static const char hex[] = "0123456789abcdef";
168171
uint8_t val = static_cast<uint8_t>(src[i]);
169-
dst[k + 0] = hex[val >> 4];
170-
dst[k + 1] = hex[val & 15];
172+
dst[k + 0] = nibble(val >> 4);
173+
dst[k + 1] = nibble(val & 15);
171174
}
172175

173176
return dlen;

0 commit comments

Comments
 (0)