Skip to content

Commit 1636580

Browse files
authored
[libc++] Avoid including <ostream> in <fstream> and <strstream> (#116014)
This reduces the include time of `<fstream>` from ~800ms to ~500ms.
1 parent 71b3b32 commit 1636580

File tree

5 files changed

+6
-26
lines changed

5 files changed

+6
-26
lines changed

libcxx/include/fstream

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,16 @@ typedef basic_fstream<wchar_t> wfstream;
193193
#include <__fwd/fstream.h>
194194
#include <__locale>
195195
#include <__memory/addressof.h>
196+
#include <__memory/unique_ptr.h>
197+
#include <__ostream/basic_ostream.h>
196198
#include <__type_traits/enable_if.h>
197199
#include <__type_traits/is_same.h>
198200
#include <__utility/move.h>
199201
#include <__utility/swap.h>
200202
#include <__utility/unreachable.h>
201203
#include <cstdio>
202204
#include <istream>
203-
#include <ostream>
205+
#include <streambuf>
204206
#include <typeinfo>
205207
#include <version>
206208

libcxx/include/strstream

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ private:
130130
*/
131131

132132
#include <__config>
133+
#include <__ostream/basic_ostream.h>
133134
#include <istream>
134-
#include <ostream>
135+
#include <streambuf>
135136
#include <version>
136137

137138
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

libcxx/test/libcxx/transitive_includes/cxx23.csv

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,11 @@ forward_list limits
410410
forward_list new
411411
forward_list tuple
412412
forward_list version
413-
fstream array
414413
fstream bitset
415414
fstream cctype
416415
fstream cerrno
417416
fstream climits
418417
fstream clocale
419-
fstream cmath
420418
fstream compare
421419
fstream cstddef
422420
fstream cstdint
@@ -427,7 +425,6 @@ fstream ctime
427425
fstream cwchar
428426
fstream cwctype
429427
fstream filesystem
430-
fstream format
431428
fstream initializer_list
432429
fstream iomanip
433430
fstream ios
@@ -436,9 +433,6 @@ fstream istream
436433
fstream limits
437434
fstream locale
438435
fstream new
439-
fstream optional
440-
fstream ostream
441-
fstream print
442436
fstream ratio
443437
fstream stdexcept
444438
fstream streambuf
@@ -1081,13 +1075,11 @@ string_view limits
10811075
string_view new
10821076
string_view stdexcept
10831077
string_view version
1084-
strstream array
10851078
strstream bitset
10861079
strstream cctype
10871080
strstream cerrno
10881081
strstream climits
10891082
strstream clocale
1090-
strstream cmath
10911083
strstream compare
10921084
strstream cstddef
10931085
strstream cstdint
@@ -1097,17 +1089,13 @@ strstream cstring
10971089
strstream ctime
10981090
strstream cwchar
10991091
strstream cwctype
1100-
strstream format
11011092
strstream initializer_list
11021093
strstream ios
11031094
strstream iosfwd
11041095
strstream istream
11051096
strstream limits
11061097
strstream locale
11071098
strstream new
1108-
strstream optional
1109-
strstream ostream
1110-
strstream print
11111099
strstream ratio
11121100
strstream stdexcept
11131101
strstream streambuf

libcxx/test/libcxx/transitive_includes/cxx26.csv

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,11 @@ forward_list limits
410410
forward_list new
411411
forward_list tuple
412412
forward_list version
413-
fstream array
414413
fstream bitset
415414
fstream cctype
416415
fstream cerrno
417416
fstream climits
418417
fstream clocale
419-
fstream cmath
420418
fstream compare
421419
fstream cstddef
422420
fstream cstdint
@@ -426,7 +424,6 @@ fstream cstring
426424
fstream ctime
427425
fstream cwchar
428426
fstream cwctype
429-
fstream format
430427
fstream initializer_list
431428
fstream iomanip
432429
fstream ios
@@ -435,9 +432,6 @@ fstream istream
435432
fstream limits
436433
fstream locale
437434
fstream new
438-
fstream optional
439-
fstream ostream
440-
fstream print
441435
fstream ratio
442436
fstream stdexcept
443437
fstream streambuf
@@ -1080,13 +1074,11 @@ string_view limits
10801074
string_view new
10811075
string_view stdexcept
10821076
string_view version
1083-
strstream array
10841077
strstream bitset
10851078
strstream cctype
10861079
strstream cerrno
10871080
strstream climits
10881081
strstream clocale
1089-
strstream cmath
10901082
strstream compare
10911083
strstream cstddef
10921084
strstream cstdint
@@ -1096,17 +1088,13 @@ strstream cstring
10961088
strstream ctime
10971089
strstream cwchar
10981090
strstream cwctype
1099-
strstream format
11001091
strstream initializer_list
11011092
strstream ios
11021093
strstream iosfwd
11031094
strstream istream
11041095
strstream limits
11051096
strstream locale
11061097
strstream new
1107-
strstream optional
1108-
strstream ostream
1109-
strstream print
11101098
strstream ratio
11111099
strstream stdexcept
11121100
strstream streambuf

libcxx/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
1111

1212
#include <cassert>
13+
#include <cerrno>
1314
#include <concepts>
1415
#include <cstdio>
1516
#include <fstream>

0 commit comments

Comments
 (0)