[ox/std] Slight optimization
This commit is contained in:
22
deps/ox/src/ox/std/strconv.hpp
vendored
22
deps/ox/src/ox/std/strconv.hpp
vendored
@@ -17,7 +17,7 @@
|
||||
namespace ox {
|
||||
|
||||
template<Integer_c Integer>
|
||||
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<Integer, 64> mod = 1000000000000000000;
|
||||
ox::ResizedInt_t<Integer, 64> 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<Integer>) {
|
||||
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<char>('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<char>(start + digit)));
|
||||
OX_RETURN_ERROR(writer.put(static_cast<char>('0' + digit)));
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user