strparse: speed up the hex parser somewhat

Around 2.3x speed-up parsing many large hexadecimal numbers. The decimal and
octal parser get marginally faster.

Still very readable, compact and easy to follow code.

Tweaks

- combine the max and the overflow check, gains 3ns/num (use a separate
  check outside of the loop instead for max < base)
- one less indirection in the pointer, gains 3ns/num
- using the table lookup for hex nums, gains 5ns/num
- unfold the num_digit() macro, gains 3s/num
- use the hexasciitable unconditionally, gains 2ns/num
- use post-increment pointer in the table lookup, gains 1ns/num
- improved valid_digit() using the table for the hex case,
  gains 26 ns/num
- use "max char" in valid_digit(), gains 3ns/num

Behavior changes:

- no longer returns STRE_TOO_BIG - only STRE_OVERFLOW
- does not move the char ** on error, which is probably better

Updated and extended test 1664 (significantly).

Closes #16374
This commit is contained in:
Daniel Stenberg 2025-02-17 22:34:21 +01:00
parent 3fd1dfc829
commit ad700a0917
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 310 additions and 56 deletions

View file

@ -995,7 +995,7 @@ static CURLcode cf_socket_ctx_init(struct cf_socket_ctx *ctx,
p = getenv("CURL_DBG_SOCK_RMAX");
if(p) {
curl_off_t l;
if(!Curl_str_number(&p, &l, SIZE_T_MAX))
if(!Curl_str_number(&p, &l, CURL_OFF_T_MAX))
ctx->recv_max = (size_t)l;
}
}