From 1f2ff0779698493d79c806219cf51a304d6e029a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Wed, 22 Nov 2023 19:31:05 +0300 Subject: [PATCH] =?UTF-8?q?mdbx++:=20=D0=BF=D0=B5=D1=80=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BA=D0=B0/=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20`to=5Fhex()`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mdbx.c++ | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mdbx.c++ b/src/mdbx.c++ index 621c2695..b3187e82 100644 --- a/src/mdbx.c++ +++ b/src/mdbx.c++ @@ -607,7 +607,7 @@ char *to_hex::write_bytes(char *__restrict const dest, size_t dest_size) const { auto ptr = dest; auto src = source.byte_ptr(); - const char alphabase = (uppercase ? 'A' : 'a') - 10; + const char alpha_shift = (uppercase ? 'A' : 'a') - '9' - 1; auto line = ptr; for (const auto end = source.end_byte_ptr(); src != end; ++src) { if (wrap_width && size_t(ptr - line) >= wrap_width) { @@ -616,8 +616,8 @@ char *to_hex::write_bytes(char *__restrict const dest, size_t dest_size) const { } const int8_t hi = *src >> 4; const int8_t lo = *src & 15; - ptr[0] = char(alphabase + hi + (((hi - 10) >> 7) & -7)); - ptr[1] = char(alphabase + lo + (((lo - 10) >> 7) & -7)); + ptr[0] = char('0' + hi + (((9 - hi) >> 7) & alpha_shift)); + ptr[1] = char('0' + lo + (((9 - lo) >> 7) & alpha_shift)); ptr += 2; assert(ptr <= dest + dest_size); } @@ -629,7 +629,7 @@ char *to_hex::write_bytes(char *__restrict const dest, size_t dest_size) const { MDBX_CXX20_LIKELY { ::std::ostream::sentry sentry(out); auto src = source.byte_ptr(); - const char alphabase = (uppercase ? 'A' : 'a') - 10; + const char alpha_shift = (uppercase ? 'A' : 'a') - '9' - 1; unsigned width = 0; for (const auto end = source.end_byte_ptr(); src != end; ++src) { if (wrap_width && width >= wrap_width) { @@ -638,8 +638,8 @@ char *to_hex::write_bytes(char *__restrict const dest, size_t dest_size) const { } const int8_t hi = *src >> 4; const int8_t lo = *src & 15; - out.put(char(alphabase + hi + (((hi - 10) >> 7) & -7))); - out.put(char(alphabase + lo + (((lo - 10) >> 7) & -7))); + out.put(char('0' + hi + (((9 - hi) >> 7) & alpha_shift))); + out.put(char('0' + lo + (((9 - lo) >> 7) & alpha_shift))); width += 2; } } @@ -670,11 +670,11 @@ char *from_hex::write_bytes(char *__restrict const dest, int8_t hi = src[0]; hi = (hi | 0x20) - 'a'; - hi += 10 + ((hi >> 7) & 7); + hi += 10 + ((hi >> 7) & 39); int8_t lo = src[1]; lo = (lo | 0x20) - 'a'; - lo += 10 + ((lo >> 7) & 7); + lo += 10 + ((lo >> 7) & 39); *ptr++ = hi << 4 | lo; src += 2;