4 Commits

Author SHA1 Message Date
Daniel Stenberg
ad700a0917
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
2025-02-19 07:49:06 +01:00
Daniel Stenberg
b4538ec522
strparse: switch to curl_off_t as base data type
- add hex and octal parsers to the Curl_str_* family
- make curlx_strtoofft use these parsers
- remove all use of strtol() and strtoul() in library code
- generally use Curl_str_* more than strtoofft, for stricter parsing
- supports 64-bit universally, instead of 'long' which differs in size
  between platforms

Extended the unit test 1664 to verify hex and octal parsing.

Closes #16336
2025-02-15 21:58:48 +01:00
Daniel Stenberg
b696fc129b
lib: use Curl_str_number() for parsing decimal numbers
Instead of strtoul() and strtol() calls.

Easier API with better integer overflow detection and built-in max check
that now comes automatic everywhere this is used.

Closes #16319
2025-02-14 10:38:56 +01:00
Daniel Stenberg
d5c738c608
strparse: string parsing helper functions
Designed to aid converting off from sscanf parsers. sscanf is hard to
use right, easy to mess up and often makes for sloppy error checking.

The new parsers allow more exact and pedandic parsing.

This new set of functions should be possible to use (and extend) and
switch over other libcurl parser code to use going forward.

Adapts the following to use the new functions:

- altsvc.c
- hsts.c
- http_aws_sigv4.c

Bonus: fewer memory copies, fewer stack buffers.

Test: Unit test1664

Docs: docs/internals/STRPARSE.md

Closes #15692
2024-12-12 16:00:52 +01:00