llvm-project/libcxx/include/__format
Mark de Wever 6589729206 [libc++][format] Improves parsing speed.
A format string like "{}" is quite common. In this case avoid parsing
the format-spec when it's not present. Before the parsing was always
called, therefore some refactoring is done to make sure the formatters
work properly when their parse member isn't called.

From the wording it's not entirely clear whether this optimization is
allowed

[tab:formatter]
```
  and the range [pc.begin(), pc.end()) from the last call to f.parse(pc).
```
Implies there's always a call to `f.parse` even when the format-spec
isn't present. Therefore this optimization isn't done for handle
classes; it's unclear whether that would break user defined formatters.

The improvements give a small reduciton is code size:
 719408	  12472	    488	 732368	  b2cd0	before
 718824	  12472	    488	 731784	  b2a88	after

The performance benefits when not using a format-spec are:

```
Comparing ./formatter_int.libcxx.out-baseline to ./formatter_int.libcxx.out
Benchmark                                                               Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------------
BM_Basic<uint32_t>                                                   -0.0688         -0.0687            67            62            67            62
BM_Basic<int32_t>                                                    -0.1105         -0.1107            73            65            73            65
BM_Basic<uint64_t>                                                   -0.1053         -0.1049            95            85            95            85
BM_Basic<int64_t>                                                    -0.0889         -0.0888            93            85            93            85
BM_BasicLow<__uint128_t>                                             -0.0655         -0.0655            96            90            96            90
BM_BasicLow<__int128_t>                                              -0.0693         -0.0694            97            90            97            90
BM_Basic<__uint128_t>                                                -0.0359         -0.0359           256           247           256           247
BM_Basic<__int128_t>                                                 -0.0414         -0.0414           239           229           239           229
```

For the cases where a format-spec is used the results remain similar,
some are faster some are slower, differing per run.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D129426
2022-07-13 17:39:09 +02:00
..
buffer.h [libc++] Make the Debug mode a configuration-time only option 2022-06-07 16:33:53 -04:00
concepts.h [libc++][format] Adds a formattable concept. 2022-05-18 20:02:08 +02:00
enable_insertable.h [libc++][format][3/6] Adds a __container_buffer. 2022-04-09 09:35:48 +02:00
format_arg.h [libc++][format] Use forwarding references. 2022-07-10 17:19:28 +02:00
format_arg_store.h [libc++][format] Use forwarding references. 2022-07-10 17:19:28 +02:00
format_args.h [libc++][format] Improve format-arg-store. 2022-05-18 20:11:36 +02:00
format_context.h [libc++][NFC] Add missing includes 2022-06-06 12:58:23 -04:00
format_error.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
format_fwd.h [libc++][format] Improve format-arg-store. 2022-05-18 20:11:36 +02:00
format_parse_context.h [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
format_string.h [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
format_to_n_result.h [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
formatter.h [libc++[format][NFC] Removes dead code. 2022-07-07 08:00:43 +02:00
formatter_bool.h [libc++][format] Improves parsing speed. 2022-07-13 17:39:09 +02:00
formatter_char.h [libc++][format] Improves parsing speed. 2022-07-13 17:39:09 +02:00
formatter_floating_point.h [libc++[format][NFC] Removes dead code. 2022-07-07 08:00:43 +02:00
formatter_integer.h [libc++][format] Implements 128-bit support. 2022-07-07 17:36:03 +02:00
formatter_integral.h [libc++][format] Improves parsing speed. 2022-07-13 17:39:09 +02:00
formatter_output.h [libc++][format] Improves parsing speed. 2022-07-13 17:39:09 +02:00
formatter_pointer.h [libc++][format] Improve pointer formatters. 2022-06-29 08:39:42 +02:00
formatter_string.h [libc++][format] Improve string formatters 2022-06-22 07:40:36 +02:00
parser_std_format_spec.h [libc++][format] Improves parsing speed. 2022-07-13 17:39:09 +02:00