forked from OSchip/llvm-project
Default raw_string_ostream to be unbuffered
raw_string_ostream can just use the std::string as a buffer. The buffer requirement came from the days when the minimum buffer size was 128 (fixed in 2015) and std::string was non-SSO. Now we can just use the inline capacity for small things and on a good growth strategy later. This assumes that the standard library isn't doing something bad like only growing to the exact size. I checked some common implementations and they grow by 2x (libc++) or 1.5x (msvc) which is reasonable. We should still check if this incurs any performance regressions though.
This commit is contained in:
parent
9caac56a65
commit
65b13610a5
|
@ -524,7 +524,9 @@ class raw_string_ostream : public raw_ostream {
|
|||
uint64_t current_pos() const override { return OS.size(); }
|
||||
|
||||
public:
|
||||
explicit raw_string_ostream(std::string &O) : OS(O) {}
|
||||
explicit raw_string_ostream(std::string &O) : OS(O) {
|
||||
SetUnbuffered();
|
||||
}
|
||||
~raw_string_ostream() override;
|
||||
|
||||
/// Flushes the stream contents to the target string and returns the string's
|
||||
|
|
|
@ -18,7 +18,10 @@ namespace {
|
|||
|
||||
template<typename T> std::string printToString(const T &Value) {
|
||||
std::string res;
|
||||
return (llvm::raw_string_ostream(res) << Value).str();
|
||||
llvm::raw_string_ostream OS(res);
|
||||
OS.SetBuffered();
|
||||
OS << Value;
|
||||
return res;
|
||||
}
|
||||
|
||||
/// printToString - Print the given value to a stream which only has \arg
|
||||
|
|
Loading…
Reference in New Issue