Re: [PATCH] vsprintf: uninline simple_strntoull(), reorder arguments

From: Andy Shevchenko
Date: Mon Oct 30 2023 - 04:59:32 EST


On Fri, Oct 27, 2023 at 05:13:58PM +0300, Alexey Dobriyan wrote:
> * uninline simple_strntoull(),
> gcc overinlines and this function is not performance critical
>
> * reorder arguments, so that appending INT_MAX as 4th argument
> generates very efficient tail call
>
> Space savings:
>
> add/remove: 1/0 grow/shrink: 0/3 up/down: 27/-179 (-152)
> Function old new delta
> simple_strntoll - 27 +27
> simple_strtoull 15 10 -5
> simple_strtoll 41 7 -34
> vsscanf 1930 1790 -140


Makes sense to me
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

...

> if (is_sign)
> - val.s = simple_strntoll(str,
> - field_width >= 0 ? field_width : INT_MAX,
> - &next, base);
> + val.s = simple_strntoll(str, &next, base,
> + field_width >= 0 ? field_width : INT_MAX);
> else
> - val.u = simple_strntoull(str,
> - field_width >= 0 ? field_width : INT_MAX,
> - &next, base);
> + val.u = simple_strntoull(str, &next, base,
> + field_width >= 0 ? field_width : INT_MAX);

Looking at these, why do we even care about signedness? field_witdh IIRC is 16-bit or less
and if size_t is to big it's still fine. No?

--
With Best Regards,
Andy Shevchenko