llvm-project/libcxx/include
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
..
__algorithm Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}" 2022-07-13 13:41:25 +02:00
__bit [libc++][NFC] Use concepts in <bit>. 2022-06-13 18:17:48 +02:00
__charconv [libc++] Implements 128-bit support in to_chars. 2022-07-07 17:32:27 +02:00
__chrono [libc++][chrono] Adds operator<=> for day. 2022-07-13 17:20:31 +02:00
__compare [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
__concepts [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
__coroutine [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__debug_utils [libc++] Make _LIBCPP_DEBUG_RANDOMIZE_RANGE a function 2022-07-03 18:03:44 +02:00
__filesystem [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
__format [libc++][format] Improves parsing speed. 2022-07-13 17:39:09 +02:00
__functional Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}" 2022-07-13 13:41:25 +02:00
__fwd [libc++][ranges] Implement `views::take`. 2022-05-06 14:16:13 -07:00
__ios [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__iterator Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}" 2022-07-13 13:41:25 +02:00
__memory [libc++] Complete the implementation of N4190 2022-06-22 10:13:03 +02:00
__numeric [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
__random [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
__ranges [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
__string Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}" 2022-07-13 13:41:25 +02:00
__support [libc++][NFC] Add MVS guard for locale_mgmt_zos.h 2022-07-12 14:15:42 -04:00
__thread [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__type_traits [libc++][NFC] Update #ifdef comments. 2022-07-10 14:08:35 +02:00
__utility [libc++] Remove macros for IBM compiler 2022-06-14 09:15:41 -04:00
__variant [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
experimental Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}" 2022-07-13 13:41:25 +02:00
ext [libc++] Don't call key_eq in unordered_map/set rehashing routine 2022-07-10 11:44:12 +02:00
CMakeLists.txt Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}" 2022-07-13 13:41:25 +02:00
__assert [libc++] Make the Debug mode a configuration-time only option 2022-06-07 16:33:53 -04:00
__availability [libc++] Removes _LIBCPP_AVAILABILITY_TO_CHARS. 2022-06-07 18:59:19 +02:00
__bit_reference [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
__bits [libc++] Implements 128-bit support in to_chars. 2022-07-07 17:32:27 +02:00
__bsd_locale_defaults.h [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__bsd_locale_fallbacks.h [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__config [libc++] Re-apply the use of ABI tags to provide per-TU insulation 2022-07-08 08:38:36 -04:00
__config_site.in [libc++] Re-apply the use of ABI tags to provide per-TU insulation 2022-07-08 08:38:36 -04:00
__debug [libc++] Make _LIBCPP_DEBUG_RANDOMIZE_RANGE a function 2022-07-03 18:03:44 +02:00
__errc [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
__hash_table [libc++] Don't call key_eq in unordered_map/set rehashing routine 2022-07-10 11:44:12 +02:00
__locale [libc++] Towards a simpler extern template story in libc++ 2022-06-08 22:05:07 -04:00
__mbstate_t.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
__mutex_base [libc++][NFC] Replace enable_if with __enable_if_t in a few places 2022-07-04 11:09:34 +02:00
__node_handle [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__split_buffer [libc++] Fix __split_buffer::__construct_at_end definition to match declaration 2022-07-05 10:19:21 +02:00
__std_stream [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__threading_support [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
__tree [libc++][NFC] Replace enable_if with __enable_if_t in a few places 2022-07-04 11:09:34 +02:00
__tuple [libc++][NFC] Replace enable_if with __enable_if_t in a few places 2022-07-04 11:09:34 +02:00
__undef_macros [libc++] Assume that push_macro and pop_macro are available 2022-05-23 20:47:44 +02:00
algorithm Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}" 2022-07-13 13:41:25 +02:00
any [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
array [libc++][NFC] Replace enable_if with __enable_if_t in a few places 2022-07-04 11:09:34 +02:00
atomic [libc++] Undeprecate ATOMIC_FLAG_INIT (LWG3659) 2022-07-12 08:00:40 +03:00
barrier [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
bit [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
bitset [libc++] Complete the implementation of N4190 2022-06-22 10:13:03 +02:00
cassert [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
ccomplex [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cctype [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cerrno [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cfenv [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cfloat [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
charconv [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
chrono [libc++][chrono] Adds operator<=> for day. 2022-07-13 17:20:31 +02:00
cinttypes [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
ciso646 [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
climits [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
clocale [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cmath [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
codecvt [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
compare [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
complex [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
complex.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
concepts [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
condition_variable [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
coroutine [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
csetjmp [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
csignal [libc++] Fix modules builds when features are removed 2022-06-08 18:48:25 -04:00
cstdarg [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cstdbool [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cstddef [libc++] Use __enable_if_t and is_integral in cstddef 2022-05-29 12:05:02 +02:00
cstdint [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cstdio [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cstdlib [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cstring [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
ctgmath [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
ctime [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
ctype.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cuchar [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cwchar [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
cwctype [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
deque [libc++] Use __is_exactly_{input, forward}_iterator 2022-07-05 10:06:27 +02:00
errno.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
exception [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
execution [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
fenv.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
filesystem [libc++] Mark standard-mandated includes as such 2022-06-17 20:43:33 +02:00
float.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
format [libc++][format] Improves parsing speed. 2022-07-13 17:39:09 +02:00
forward_list [libc++][NFC] Replace enable_if with __enable_if_t in a few places 2022-07-04 11:09:34 +02:00
fstream [libc++] Towards a simpler extern template story in libc++ 2022-06-08 22:05:07 -04:00
functional [libc++][ranges] Finish LWG issues directly related to the One Ranges Proposal. 2022-06-28 12:00:15 -07:00
future [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
initializer_list [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
inttypes.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
iomanip [libc++] Granularize __string 2022-06-09 21:04:18 +02:00
ios [libc++] Mark standard-mandated includes as such 2022-06-17 20:43:33 +02:00
iosfwd [libc++] Remove macros for IBM compiler 2022-06-14 09:15:41 -04:00
iostream [libc++] Mark standard-mandated includes as such 2022-06-17 20:43:33 +02:00
istream [libc++] Granularize <iterator> includes 2022-06-10 22:43:57 +02:00
iterator [libc++][ranges] Finish LWG issues directly related to the One Ranges Proposal. 2022-06-28 12:00:15 -07:00
latch [libc++] Make sure that all headers can be included with modules enabled 2022-05-25 03:44:48 -04:00
limits [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
limits.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
list [libc++][NFC] Replace enable_if with __enable_if_t in a few places 2022-07-04 11:09:34 +02:00
locale [libc++] Implement P0618R0 (Deprecating <codecvt>) 2022-06-30 16:47:50 +02:00
locale.h [libc++] Improve error messages for disabled modes 2022-05-20 09:36:55 -04:00
map [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
math.h [libc++][AIX] Use C++ overloads from libc++'s math.h 2022-03-01 15:53:41 -05:00
memory [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
module.modulemap.in Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}" 2022-07-13 13:41:25 +02:00
mutex [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
new [libc++] Implement P0154R1 (Hardware inference size) 2022-06-23 01:31:09 +02:00
numbers [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
numeric [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
optional [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
ostream [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
queue [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
random [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
ranges [libc++] add zip_view and views::zip for C++23 2022-04-25 12:22:22 +02:00
ratio [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
regex [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
scoped_allocator [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
semaphore [libc++] Make sure that all headers can be included with modules enabled 2022-05-25 03:44:48 -04:00
set [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
setjmp.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
shared_mutex [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
span [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
sstream [libc++] Towards a simpler extern template story in libc++ 2022-06-08 22:05:07 -04:00
stack [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
stdatomic.h [libc++] Remove overly conservative error in <stdatomic.h> 2022-05-16 15:30:01 -04:00
stdbool.h [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
stddef.h [libc++] Remove the ability to use the std::nullptr_t emulation in C++03 mode 2022-02-07 17:51:05 -05:00
stdexcept [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
stdint.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
stdio.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
stdlib.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
streambuf [libc++] Towards a simpler extern template story in libc++ 2022-06-08 22:05:07 -04:00
string [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
string.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
string_view [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
strstream [libc++][clang-tidy] Enable bugprone-use-after-move and explicitly list all used checks 2022-06-21 20:25:04 +02:00
system_error [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
tgmath.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
thread [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
tuple [libc++][NFC] Replace enable_if with __enable_if_t in a few places 2022-07-04 11:09:34 +02:00
type_traits [libc++] Remove dead code and unneeded C++03 specializations from type_traits 2022-06-30 16:49:17 +02:00
typeindex [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
typeinfo [libc++] Ensure that all public C++ headers include <__assert> 2022-03-30 15:05:31 -04:00
uchar.h [libc++] Add missing header <cuchar> 2022-03-07 08:48:50 -05:00
unordered_map [libc++] Don't call key_eq in unordered_map/set rehashing routine 2022-07-10 11:44:12 +02:00
unordered_set [libc++] Don't call key_eq in unordered_map/set rehashing routine 2022-07-10 11:44:12 +02:00
utility [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
valarray [libc++] Re-add transitive includes that had been removed since LLVM 14 2022-06-27 22:18:19 -04:00
variant [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
vector [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
version [libc++] Implement P0154R1 (Hardware inference size) 2022-06-23 01:31:09 +02:00
wchar.h [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
wctype.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00