Skip to content

[llvm] Avoid 'raw_string_ostream::str()' (NFC) #97203

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 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class DWARFContext : public DIContext {
for (unsigned Size : DWARFContext::getSupportedAddressSizes())
Stream << LS << Size;
Stream << ')';
return make_error<StringError>(Stream.str(), EC);
return make_error<StringError>(Buffer, EC);
}

std::shared_ptr<DWARFContext> getDWOContext(StringRef AbsolutePath);
Expand Down
10 changes: 5 additions & 5 deletions llvm/include/llvm/Support/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ErrorInfoBase {
std::string Msg;
raw_string_ostream OS(Msg);
log(OS);
return OS.str();
return Msg;
}

/// Convert this error to a std::error_code.
Expand Down Expand Up @@ -761,7 +761,7 @@ inline void cantFail(Error Err, const char *Msg = nullptr) {
std::string Str;
raw_string_ostream OS(Str);
OS << Msg << "\n" << Err;
Msg = OS.str().c_str();
Msg = Str.c_str();
#endif
llvm_unreachable(Msg);
}
Expand Down Expand Up @@ -792,7 +792,7 @@ T cantFail(Expected<T> ValOrErr, const char *Msg = nullptr) {
raw_string_ostream OS(Str);
auto E = ValOrErr.takeError();
OS << Msg << "\n" << E;
Msg = OS.str().c_str();
Msg = Str.c_str();
#endif
llvm_unreachable(Msg);
}
Expand Down Expand Up @@ -823,7 +823,7 @@ T& cantFail(Expected<T&> ValOrErr, const char *Msg = nullptr) {
raw_string_ostream OS(Str);
auto E = ValOrErr.takeError();
OS << Msg << "\n" << E;
Msg = OS.str().c_str();
Msg = Str.c_str();
#endif
llvm_unreachable(Msg);
}
Expand Down Expand Up @@ -1338,7 +1338,7 @@ class FileError final : public ErrorInfo<FileError> {
std::string Msg;
raw_string_ostream OS(Msg);
Err->log(OS);
return OS.str();
return Msg;
}

StringRef getFileName() const { return FileName; }
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Support/GraphWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ class GraphWriter {
O << "|";

if (RenderUsingHTML)
O << EdgeSourceLabels.str();
O << edgeSourceLabels;
else
O << "{" << EdgeSourceLabels.str() << "}";
O << "{" << edgeSourceLabels << "}";

if (DTraits.renderGraphFromBottomUp())
if (!RenderUsingHTML)
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/ScopedPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ template <class T> std::string to_string(const T &Value) {
std::string number;
raw_string_ostream stream(number);
stream << Value;
return stream.str();
return number;
}

template <typename T, typename TEnum>
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Support/YAMLTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ yamlize(IO &YamlIO, T &Val, bool, EmptyContext &Ctx) {
std::string Storage;
raw_string_ostream Buffer(Storage);
BlockScalarTraits<T>::output(Val, YamlIO.getContext(), Buffer);
StringRef Str = Buffer.str();
StringRef Str(Storage);
YamlIO.blockScalarString(Str);
} else {
StringRef Str;
Expand All @@ -1046,8 +1046,8 @@ yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
raw_string_ostream ScalarBuffer(ScalarStorage), TagBuffer(TagStorage);
TaggedScalarTraits<T>::output(Val, io.getContext(), ScalarBuffer,
TagBuffer);
io.scalarTag(TagBuffer.str());
StringRef ScalarStr = ScalarBuffer.str();
io.scalarTag(TagStorage);
StringRef ScalarStr(ScalarStorage);
io.scalarString(ScalarStr,
TaggedScalarTraits<T>::mustQuote(Val, ScalarStr));
} else {
Expand Down
Loading