[PATCH 3/3] resolv: Optimize inet_ntop
Paul Eggert
eggert@cs.ucla.edu
Tue Jun 3 22:27:42 GMT 2025
On 6/3/25 12:51, Adhemerval Zanella wrote:
> static inline char *put_uint8 (uint8_t word, char *tp)
Put the function name at the start of a line.
> + intptr_t s = 1;
There should be no need for intptr_t; 'int' is good enough and clearer
and should generate the same machine code.
> + tp[2] = _itoa_lower_digits[word % 10];
Don't consult an array; just add '0'.
> + if (word >= 100)
> ...
> + if (word >= 10)
Since this is for performance, shouldn't the code avoid conditional
branches? Something like the following, say:
static inline char *
put_uint8 (uint8_t word, char *tp)
{
*tp = '0' + word / 100;
tp += 100 <= word;
*tp = '0' + word / 10 % 10;
tp += 10 <= word;
*tp++ = '0' + word % 10;
return tp;
}
Alternatively, if we're going to have conditional branches, there is no
need to test (word >= 100) if (word >= 10) is false.
More information about the Libc-alpha
mailing list