]> git.ipfire.org Git - thirdparty/curl.git/commit
strparse: speed up the hex parser somewhat
authorDaniel Stenberg <daniel@haxx.se>
Mon, 17 Feb 2025 21:34:21 +0000 (22:34 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 19 Feb 2025 06:49:06 +0000 (07:49 +0100)
commitad700a091788612017a4760ea4f81cbe8fb413ce
tree09927cb9e70ac6567a10b88c55b14081d88b81c0
parent3fd1dfc829cec86fd74e0e2973d286c59bcb9b92
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
lib/cf-socket.c
lib/cfilters.c
lib/request.c
lib/strparse.c
tests/data/test1664
tests/unit/unit1664.c