Skip to content

Commit b7b7f60

Browse files
rupprechtPriyanshu3820
authored andcommitted
[libc++] Revert fstream::read optimizations (llvm#168894)
This causes various runtime failures, as reported in llvm#168628. This reverts both llvm#165223 and llvm#167779
1 parent e6d5ff9 commit b7b7f60

File tree

5 files changed

+6
-43
lines changed

5 files changed

+6
-43
lines changed

libcxx/docs/ReleaseNotes/22.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Improvements and New Features
6767
by up to 2.5x
6868
- The performance of ``erase(iterator, iterator)`` in the unordered containers has been improved by up to 1.9x
6969
- The performance of ``map::insert_or_assign`` has been improved by up to 2x
70-
- ``ofstream::write`` and ``ifstream::read`` have been optimized to pass through large reads and writes to system calls
71-
directly instead of copying them in chunks.
70+
- ``ofstream::write`` has been optimized to pass through large strings to system calls directly instead of copying them
71+
in chunks into a buffer.
7272
- Multiple internal types have been refactored to use ``[[no_unique_address]]``, resulting in faster compile times and
7373
reduced debug information.
7474

libcxx/include/fstream

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -308,25 +308,6 @@ protected:
308308
return basic_streambuf<_CharT, _Traits>::xsputn(__str, __len);
309309
}
310310

311-
_LIBCPP_HIDE_FROM_ABI_VIRTUAL streamsize xsgetn(char_type* __str, streamsize __len) override {
312-
if (__always_noconv_) {
313-
const streamsize __n = std::min(this->egptr() - this->gptr(), __len);
314-
if (__n != 0) {
315-
traits_type::copy(__str, this->gptr(), __n);
316-
this->__gbump_ptrdiff(__n);
317-
}
318-
const streamsize __remainder = __len - __n;
319-
const streamsize __buffer_space = this->egptr() - this->eback();
320-
321-
if (__remainder >= __buffer_space)
322-
return std::fread(__str + __n, sizeof(char_type), __remainder, __file_) + __n;
323-
else if (__remainder > 0)
324-
return basic_streambuf<_CharT, _Traits>::xsgetn(__str + __n, __remainder) + __n;
325-
return __n;
326-
}
327-
return basic_streambuf<_CharT, _Traits>::xsgetn(__str, __len);
328-
}
329-
330311
private:
331312
char* __extbuf_;
332313
const char* __extbufnext_;

libcxx/test/benchmarks/streams/fstream.bench.cpp renamed to libcxx/test/benchmarks/streams/ofstream.bench.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <benchmark/benchmark.h>
1313

14-
static void bm_ofstream_write(benchmark::State& state) {
14+
static void bm_write(benchmark::State& state) {
1515
std::vector<char> buffer;
1616
buffer.resize(16384);
1717

@@ -20,24 +20,6 @@ static void bm_ofstream_write(benchmark::State& state) {
2020
for (auto _ : state)
2121
stream.write(buffer.data(), buffer.size());
2222
}
23-
BENCHMARK(bm_ofstream_write);
24-
25-
static void bm_ifstream_read(benchmark::State& state) {
26-
std::vector<char> buffer;
27-
buffer.resize(16384);
28-
29-
std::ofstream gen_testfile("testfile");
30-
gen_testfile.write(buffer.data(), buffer.size());
31-
32-
std::ifstream stream("testfile");
33-
assert(stream);
34-
35-
for (auto _ : state) {
36-
stream.read(buffer.data(), buffer.size());
37-
benchmark::DoNotOptimize(buffer);
38-
stream.seekg(0);
39-
}
40-
}
41-
BENCHMARK(bm_ifstream_read);
23+
BENCHMARK(bm_write);
4224

4325
BENCHMARK_MAIN();

libcxx/test/libcxx/input.output/file.streams/fstreams/filebuf/traits_mismatch.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
std::basic_filebuf<char, std::char_traits<wchar_t> > f;
2121
// expected-error-re@*:* {{static assertion failed{{.*}}traits_type::char_type must be the same type as CharT}}
22-
// expected-error@*:* 11 {{only virtual member functions can be marked 'override'}}
22+
// expected-error@*:* 10 {{only virtual member functions can be marked 'override'}}

libcxx/test/libcxx/input.output/file.streams/fstreams/traits_mismatch.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ std::basic_fstream<char, std::char_traits<wchar_t> > f;
2121
// expected-error-re@*:* {{static assertion failed{{.*}}traits_type::char_type must be the same type as CharT}}
2222
// expected-error-re@*:* {{static assertion failed{{.*}}traits_type::char_type must be the same type as CharT}}
2323

24-
// expected-error@*:* 13 {{only virtual member functions can be marked 'override'}}
24+
// expected-error@*:* 12 {{only virtual member functions can be marked 'override'}}
2525

2626
// FIXME: As of commit r324062 Clang incorrectly generates a diagnostic about mismatching
2727
// exception specifications for types which are already invalid for one reason or another.

0 commit comments

Comments
 (0)