From fe74ddbb0fb06d1b10ab9e604cf53b1ef7dcf1cc Mon Sep 17 00:00:00 2001 From: Nikita Skovoroda Date: Sun, 1 Feb 2026 11:25:59 +0400 Subject: [PATCH 1/3] deps: try different HexEncode impl --- deps/nbytes/src/nbytes.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/deps/nbytes/src/nbytes.cpp b/deps/nbytes/src/nbytes.cpp index a827809adbacd3..4556ee7586b440 100644 --- a/deps/nbytes/src/nbytes.cpp +++ b/deps/nbytes/src/nbytes.cpp @@ -157,6 +157,10 @@ const int8_t unhex_table[256] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; +inline char nibble(uint8_t x) { + return x + '0' + ((x > 9) * 39); +} + size_t HexEncode(const char *src, size_t slen, char *dst, size_t dlen) { // We know how much we'll write, just make sure that there's space. NBYTES_ASSERT_TRUE(dlen >= MultiplyWithOverflowCheck(slen, 2u) && @@ -164,10 +168,9 @@ size_t HexEncode(const char *src, size_t slen, char *dst, size_t dlen) { dlen = slen * 2; for (size_t i = 0, k = 0; k < dlen; i += 1, k += 2) { - static const char hex[] = "0123456789abcdef"; uint8_t val = static_cast(src[i]); - dst[k + 0] = hex[val >> 4]; - dst[k + 1] = hex[val & 15]; + dst[k + 0] = nibble(val >> 4); + dst[k + 1] = nibble(val & 15); } return dlen; From 6875893076cbaf497d503baba4ae3c8d9be9c443 Mon Sep 17 00:00:00 2001 From: Nikita Skovoroda Date: Mon, 2 Feb 2026 21:53:05 +0400 Subject: [PATCH 2/3] fixup!: ifs --- deps/nbytes/src/nbytes.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/deps/nbytes/src/nbytes.cpp b/deps/nbytes/src/nbytes.cpp index 4556ee7586b440..66bc48f4272930 100644 --- a/deps/nbytes/src/nbytes.cpp +++ b/deps/nbytes/src/nbytes.cpp @@ -157,8 +157,12 @@ const int8_t unhex_table[256] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; -inline char nibble(uint8_t x) { - return x + '0' + ((x > 9) * 39); +inline constexpr char nibble(uint8_t x) { + auto v = x + '0'; + if (x > 9) { + v += 'a' - '0' - 10; + } + return v; } size_t HexEncode(const char *src, size_t slen, char *dst, size_t dlen) { From 3d93f06d7fcd863f465e41163897759573fe2da8 Mon Sep 17 00:00:00 2001 From: Nikita Skovoroda Date: Tue, 3 Feb 2026 01:00:15 +0400 Subject: [PATCH 3/3] fixup!: ternary --- deps/nbytes/src/nbytes.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/deps/nbytes/src/nbytes.cpp b/deps/nbytes/src/nbytes.cpp index 66bc48f4272930..09e2665f8c67e4 100644 --- a/deps/nbytes/src/nbytes.cpp +++ b/deps/nbytes/src/nbytes.cpp @@ -158,11 +158,8 @@ const int8_t unhex_table[256] = { -1, -1, -1, -1, -1, -1, -1, -1, -1}; inline constexpr char nibble(uint8_t x) { - auto v = x + '0'; - if (x > 9) { - v += 'a' - '0' - 10; - } - return v; + uint8_t add = (x >= 10) ? ('a' - 10) : '0'; + return x + add; } size_t HexEncode(const char *src, size_t slen, char *dst, size_t dlen) {