inetaddr_host_lim() and inetaddr_host_lim_ret() were introduced in 1.4.4
by commit
d54bbdce87 ("[MINOR] add very fast IP parsing functions") as
fast parsers for some specific use cases. They expect a delimiter after
the IP address (cr/lf/nul/whatever, in fact, anything not a digit), and
this is how they're currently used. As noted by Md. Raisul Islam Mobin,
they could also be misused by external code not aware of this limitation
which by then saved a few CPU cycles per address at an era where they
were still precious, so let's test the end pointer before reading the
digit to make it more future-proof. If this speed still matters, these
ones could probably be rewritten to benefit from automatic vectorization
on SIMD-capable machines.
p = text;
while (1) {
- if (((unsigned)(*p - '0')) <= 9 && p < stop) {
+ while (p < stop && ((unsigned)(*p - '0')) <= 9)
p++;
- continue;
- }
/* here, we have a complete byte between <text> and <p> (exclusive) */
if (p == text)
p = text;
while (1) {
- if (((unsigned)(*p - '0')) <= 9 && p < stop) {
+ while (p < stop && ((unsigned)(*p - '0')) <= 9)
p++;
- continue;
- }
/* here, we have a complete byte between <text> and <p> (exclusive) */
if (p == text)