From 6a42303239c7dcce532ef497329b45fe552482e8 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 23 Jan 2026 01:38:31 -0600 Subject: [PATCH] [ox/std] Slight optimization --- deps/ox/src/ox/std/strconv.hpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/deps/ox/src/ox/std/strconv.hpp b/deps/ox/src/ox/std/strconv.hpp index e160d947..614b4c75 100644 --- a/deps/ox/src/ox/std/strconv.hpp +++ b/deps/ox/src/ox/std/strconv.hpp @@ -17,7 +17,7 @@ namespace ox { template -constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept { +constexpr ox::Error writeItoa(Integer const v, ox::Writer_c auto &writer) noexcept { if (v) { ox::ResizedInt_t mod = 1000000000000000000; ox::ResizedInt_t val = v; @@ -27,17 +27,23 @@ constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept { OX_RETURN_ERROR(writer.put('-')); val = ~val + 1; } - while (mod) { + if constexpr(sizeof(v) == 8 && !ox::is_signed_v) { auto digit = val / mod; val %= mod; mod /= base; + if (digit) { + digit -= 10; + OX_RETURN_ERROR(writer.put('1')); + OX_RETURN_ERROR(writer.put(static_cast('0' + digit))); + ++it; + } + } + while (mod) { + auto const digit = val / mod; + val %= mod; + mod /= base; if (it || digit) { - constexpr auto start = '0'; - if (digit >= 10) [[unlikely]] { - digit -= 10; - OX_RETURN_ERROR(writer.put('1')); - } - OX_RETURN_ERROR(writer.put(static_cast(start + digit))); + OX_RETURN_ERROR(writer.put(static_cast('0' + digit))); ++it; } }