-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Optimize std::getline #121346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[libc++] Optimize std::getline #121346
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03 | ||
|
||
#include <istream> | ||
#include <sstream> | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
void BM_getline_string(benchmark::State& state) { | ||
std::istringstream iss; | ||
|
||
std::string str; | ||
str.reserve(128); | ||
iss.str("A long string to let getline do some more work, making sure that longer strings are parsed fast enough"); | ||
|
||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(iss); | ||
|
||
std::getline(iss, str); | ||
benchmark::DoNotOptimize(str); | ||
iss.seekg(0); | ||
} | ||
} | ||
|
||
BENCHMARK(BM_getline_string); | ||
|
||
BENCHMARK_MAIN(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef TEST_SUPPORT_STREAM_TYPES_H | ||
#define TEST_SUPPORT_STREAM_TYPES_H | ||
|
||
#include <streambuf> | ||
#include <string> | ||
#include <utility> | ||
|
||
template <class CharT> | ||
class non_buffering_streambuf : public std::basic_streambuf<CharT> { | ||
using char_type = CharT; | ||
using traits_type = std::char_traits<CharT>; | ||
using int_type = typename traits_type::int_type; | ||
|
||
public: | ||
non_buffering_streambuf(std::basic_string<char_type> underlying_data) | ||
: underlying_data_(std::move(underlying_data)), index_(0) {} | ||
|
||
protected: | ||
int_type underflow() override { | ||
if (index_ != underlying_data_.size()) | ||
return underlying_data_[index_]; | ||
return traits_type::eof(); | ||
} | ||
|
||
int_type uflow() override { | ||
if (index_ != underlying_data_.size()) | ||
return underlying_data_[index_++]; | ||
return traits_type::eof(); | ||
} | ||
|
||
private: | ||
std::basic_string<char_type> underlying_data_; | ||
size_t index_; | ||
}; | ||
|
||
#endif // TEST_SUPPORT_STREAM_TYPES_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philnik777 Should this change be cherry-picked on to release/20.x branch or will that happen automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we cherry-pick this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's release-noted in the LLVM 20 release notes, but I guess it landed later than expected so it should actually have been documented in the LLVM 21 release notes. Is that possible? If so, let's move the release notes to the right file.