mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-pack (u64tostr): reimplement the function
- direct conversion of single digit numbers - remove unnecessary update of `line` variable - simplify the body according to the assertion
This commit is contained in:
@@ -293,23 +293,22 @@ u64tostr(char *buf, size_t len, uint64_t n)
|
||||
#ifdef MRB_NO_STDIO
|
||||
mrb_assert(len > 0);
|
||||
|
||||
if (n < 10) {
|
||||
buf[0] = '0' + n;
|
||||
buf[1] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
char *bufend = buf + len;
|
||||
char *p = bufend - 1;
|
||||
|
||||
*p-- = '\0';
|
||||
len--;
|
||||
|
||||
if (n > 0) {
|
||||
for (; len > 0 && n > 0; len--, n /= 10) {
|
||||
*p-- = '0' + (n % 10);
|
||||
}
|
||||
p++;
|
||||
for (; len > 0 && n > 0; len--, n /= 10) {
|
||||
*p-- = '0' + (n % 10);
|
||||
}
|
||||
else if (len > 0) {
|
||||
*p = '0';
|
||||
len--;
|
||||
}
|
||||
|
||||
p++;
|
||||
memmove(buf, p, bufend - p);
|
||||
#else
|
||||
snprintf(buf, len, "%" PRIu64, n);
|
||||
|
||||
Reference in New Issue
Block a user