Skip to content

Commit 4bd6795

Browse files
committed
[libc++][format] Implements P3107R5 in <print>.
The followup paper P3235R3 which is voted in as a DR changes the names foo_locking to foo_buffered. These changes have been applied in this patch. Before ------------------------------------------------------- Benchmark Time CPU Iterations ------------------------------------------------------- printf 71.3 ns 71.3 ns 9525175 print_string 226 ns 226 ns 3105850 print_stack 232 ns 232 ns 3026498 print_direct 530 ns 530 ns 1318447 After ------------------------------------------------------- Benchmark Time CPU Iterations ------------------------------------------------------- printf 70.6 ns 70.6 ns 9789585 print_string 222 ns 222 ns 3147678 print_stack 227 ns 227 ns 3084767 print_direct 474 ns 474 ns 1472786 Note: The performance of libc++'s std::print is still extemely slow compared to printf. Based on P3107R5 std::print should outperform printf. The main culprit is the call to isatty, which is resolved after implementing LWG4044 Confusing requirements for std::print on POSIX platforms Implements - P3107R5 - Permit an efficient implementation of ``std::print`` Implements parts of - P3235R3 std::print more types faster with less memory Fixes: #105435
1 parent 97732a4 commit 4bd6795

File tree

11 files changed

+295
-13
lines changed

11 files changed

+295
-13
lines changed

libcxx/docs/ReleaseNotes/21.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Implemented Papers
4040

4141
- N4258: Cleaning-up noexcept in the Library (`Github <https://github.com/llvm/llvm-project/issues/99937>`__)
4242
- P1361R2: Integration of chrono with text formatting (`Github <https://github.com/llvm/llvm-project/issues/100014>`__)
43+
- P3107R5 - Permit an efficient implementation of ``std::print`` (`Github <https://github.com/llvm/llvm-project/issues/105435>`__)
4344

4445
Improvements and New Features
4546
-----------------------------

libcxx/include/__format/buffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <__algorithm/copy_n.h>
1414
#include <__algorithm/fill_n.h>
15+
#include <__algorithm/for_each.h>
1516
#include <__algorithm/max.h>
1617
#include <__algorithm/min.h>
1718
#include <__algorithm/ranges_copy.h>
@@ -34,11 +35,13 @@
3435
#include <__memory/construct_at.h>
3536
#include <__memory/destroy.h>
3637
#include <__memory/uninitialized_algorithms.h>
38+
#include <__system_error/system_error.h>
3739
#include <__type_traits/add_pointer.h>
3840
#include <__type_traits/conditional.h>
3941
#include <__utility/exception_guard.h>
4042
#include <__utility/move.h>
4143
#include <stdexcept>
44+
#include <stdio.h> // Uses the POSIX/Windows unlocked stream I/O
4245
#include <string_view>
4346

4447
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

libcxx/include/print

Lines changed: 257 additions & 12 deletions
Large diffs are not rendered by default.

libcxx/modules/std/print.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export namespace std {
1616
using std::vprint_nonunicode;
1717
# if _LIBCPP_HAS_UNICODE
1818
using std::vprint_unicode;
19+
using std::vprint_unicode_buffered;
1920
# endif // _LIBCPP_HAS_UNICODE
2021
#endif // _LIBCPP_STD_VER >= 23
2122
} // namespace std

libcxx/test/libcxx/system_reserved_names.gen.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
#define __acquire SYSTEM_RESERVED_NAME
120120
#define __release SYSTEM_RESERVED_NAME
121121
122+
// Android and FreeBSD use this for __attribute__((__unused__))
123+
#if !defined(__FreeBSD__) && !defined(__ANDROID__)
124+
#define __unused SYSTEM_RESERVED_NAME
125+
#endif
126+
122127
// These names are not reserved, so the user can macro-define them.
123128
// These are intended to find improperly _Uglified template parameters.
124129
#define A SYSTEM_RESERVED_NAME

libcxx/test/libcxx/transitive_includes/cxx03.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,19 @@ atomic ratio
122122
atomic type_traits
123123
atomic version
124124
barrier atomic
125+
barrier cctype
125126
barrier climits
126127
barrier cmath
127128
barrier compare
128129
barrier concepts
129130
barrier cstddef
130131
barrier cstdint
132+
barrier cstdio
131133
barrier cstdlib
132134
barrier cstring
133135
barrier ctime
136+
barrier cwchar
137+
barrier cwctype
134138
barrier exception
135139
barrier initializer_list
136140
barrier iosfwd
@@ -2024,6 +2028,7 @@ stdexcept new
20242028
stdexcept type_traits
20252029
stdexcept typeinfo
20262030
stdexcept version
2031+
stop_token cstddef
20272032
stop_token iosfwd
20282033
stop_token version
20292034
streambuf algorithm

libcxx/test/libcxx/transitive_includes/cxx11.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,19 @@ atomic ratio
122122
atomic type_traits
123123
atomic version
124124
barrier atomic
125+
barrier cctype
125126
barrier climits
126127
barrier cmath
127128
barrier compare
128129
barrier concepts
129130
barrier cstddef
130131
barrier cstdint
132+
barrier cstdio
131133
barrier cstdlib
132134
barrier cstring
133135
barrier ctime
136+
barrier cwchar
137+
barrier cwctype
134138
barrier exception
135139
barrier initializer_list
136140
barrier iosfwd
@@ -2024,6 +2028,7 @@ stdexcept new
20242028
stdexcept type_traits
20252029
stdexcept typeinfo
20262030
stdexcept version
2031+
stop_token cstddef
20272032
stop_token iosfwd
20282033
stop_token version
20292034
streambuf algorithm

libcxx/test/libcxx/transitive_includes/cxx14.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,19 @@ atomic ratio
125125
atomic type_traits
126126
atomic version
127127
barrier atomic
128+
barrier cctype
128129
barrier climits
129130
barrier cmath
130131
barrier compare
131132
barrier concepts
132133
barrier cstddef
133134
barrier cstdint
135+
barrier cstdio
134136
barrier cstdlib
135137
barrier cstring
136138
barrier ctime
139+
barrier cwchar
140+
barrier cwctype
137141
barrier exception
138142
barrier initializer_list
139143
barrier iosfwd
@@ -2064,6 +2068,7 @@ stdexcept new
20642068
stdexcept type_traits
20652069
stdexcept typeinfo
20662070
stdexcept version
2071+
stop_token cstddef
20672072
stop_token iosfwd
20682073
stop_token version
20692074
streambuf algorithm

libcxx/test/libcxx/transitive_includes/cxx17.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,19 @@ atomic ratio
122122
atomic type_traits
123123
atomic version
124124
barrier atomic
125+
barrier cctype
125126
barrier climits
126127
barrier cmath
127128
barrier compare
128129
barrier concepts
129130
barrier cstddef
130131
barrier cstdint
132+
barrier cstdio
131133
barrier cstdlib
132134
barrier cstring
133135
barrier ctime
136+
barrier cwchar
137+
barrier cwctype
134138
barrier exception
135139
barrier initializer_list
136140
barrier iosfwd
@@ -2077,6 +2081,7 @@ stdexcept new
20772081
stdexcept type_traits
20782082
stdexcept typeinfo
20792083
stdexcept version
2084+
stop_token cstddef
20802085
stop_token iosfwd
20812086
stop_token version
20822087
streambuf algorithm

libcxx/test/libcxx/transitive_includes/cxx23.csv

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ istream ios
556556
istream iosfwd
557557
istream limits
558558
istream locale
559-
560559
istream ratio
561560
istream stdexcept
562561
istream streambuf
@@ -765,6 +764,7 @@ queue deque
765764
queue initializer_list
766765
queue iosfwd
767766
queue limits
767+
queue optional
768768
queue stdexcept
769769
queue string
770770
queue string_view
@@ -831,6 +831,7 @@ regex deque
831831
regex initializer_list
832832
regex iosfwd
833833
regex limits
834+
regex optional
834835
regex stdexcept
835836
regex string
836837
regex string_view
@@ -1075,6 +1076,7 @@ thread iosfwd
10751076
thread istream
10761077
thread limits
10771078
thread locale
1079+
thread optional
10781080
thread ratio
10791081
thread sstream
10801082
thread stdexcept
@@ -1146,6 +1148,7 @@ vector cwctype
11461148
vector initializer_list
11471149
vector iosfwd
11481150
vector limits
1151+
vector optional
11491152
vector stdexcept
11501153
vector string
11511154
vector string_view

libcxx/test/libcxx/transitive_includes/cxx26.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ queue deque
763763
queue initializer_list
764764
queue iosfwd
765765
queue limits
766+
queue optional
766767
queue stdexcept
767768
queue string
768769
queue string_view
@@ -829,6 +830,7 @@ regex deque
829830
regex initializer_list
830831
regex iosfwd
831832
regex limits
833+
regex optional
832834
regex stdexcept
833835
regex string
834836
regex string_view
@@ -1073,6 +1075,7 @@ thread iosfwd
10731075
thread istream
10741076
thread limits
10751077
thread locale
1078+
thread optional
10761079
thread ratio
10771080
thread sstream
10781081
thread stdexcept
@@ -1144,6 +1147,7 @@ vector cwctype
11441147
vector initializer_list
11451148
vector iosfwd
11461149
vector limits
1150+
vector optional
11471151
vector stdexcept
11481152
vector string
11491153
vector string_view

0 commit comments

Comments
 (0)