[polly] Tidy uses of raw_string_ostream (NFC)

As specified in the docs,
1) raw_string_ostream is always unbuffered and
2) the underlying buffer may be used directly

( 65b13610a5226b84889b923bae884ba395ad084d for further reference )

* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
This commit is contained in:
Youngsuk Kim 2024-09-17 09:53:07 -05:00
parent 848cec11f5
commit 53bc35a80a
4 changed files with 6 additions and 9 deletions

View File

@ -89,7 +89,6 @@ template <typename T> std::string operator+(Twine LHS, const T &RHS) {
std::string Buf; std::string Buf;
raw_string_ostream fmt(Buf); raw_string_ostream fmt(Buf);
fmt << RHS; fmt << RHS;
fmt.flush();
return LHS.concat(Buf).str(); return LHS.concat(Buf).str();
} }
@ -669,7 +668,7 @@ std::string ReportAlias::formatInvalidAlias(std::string Prefix,
OS << Suffix; OS << Suffix;
return OS.str(); return Message;
} }
std::string ReportAlias::getRemarkName() const { return "Alias"; } std::string ReportAlias::getRemarkName() const { return "Alias"; }

View File

@ -1818,11 +1818,9 @@ std::pair<std::string, std::string> Scop::getEntryExitStr() const {
raw_string_ostream EntryStr(EntryName); raw_string_ostream EntryStr(EntryName);
R.getEntry()->printAsOperand(EntryStr, false); R.getEntry()->printAsOperand(EntryStr, false);
EntryStr.str();
if (R.getExit()) { if (R.getExit()) {
R.getExit()->printAsOperand(ExitStr, false); R.getExit()->printAsOperand(ExitStr, false);
ExitStr.str();
} else } else
ExitName = "FunctionExit"; ExitName = "FunctionExit";

View File

@ -645,7 +645,7 @@ static std::string getInstName(Value *Val) {
std::string Result; std::string Result;
raw_string_ostream OS(Result); raw_string_ostream OS(Result);
Val->printAsOperand(OS, false); Val->printAsOperand(OS, false);
return OS.str(); return Result;
} }
void BlockGenerator::generateBeginStmtTrace(ScopStmt &Stmt, LoopToScevMapT &LTS, void BlockGenerator::generateBeginStmtTrace(ScopStmt &Stmt, LoopToScevMapT &LTS,

View File

@ -116,12 +116,12 @@ static json::Array exportArrays(const Scop &S) {
} }
for (; i < SAI->getNumberOfDimensions(); i++) { for (; i < SAI->getNumberOfDimensions(); i++) {
SAI->getDimensionSize(i)->print(RawStringOstream); SAI->getDimensionSize(i)->print(RawStringOstream);
Sizes.push_back(RawStringOstream.str()); Sizes.push_back(Buffer);
Buffer.clear(); Buffer.clear();
} }
Array["sizes"] = std::move(Sizes); Array["sizes"] = std::move(Sizes);
SAI->getElementType()->print(RawStringOstream); SAI->getElementType()->print(RawStringOstream);
Array["type"] = RawStringOstream.str(); Array["type"] = Buffer;
Buffer.clear(); Buffer.clear();
Arrays.push_back(std::move(Array)); Arrays.push_back(std::move(Array));
} }
@ -575,14 +575,14 @@ static bool areArraysEqual(ScopArrayInfo *SAI, const json::Object &Array) {
for (unsigned i = 1; i < Array.getArray("sizes")->size(); i++) { for (unsigned i = 1; i < Array.getArray("sizes")->size(); i++) {
SAI->getDimensionSize(i)->print(RawStringOstream); SAI->getDimensionSize(i)->print(RawStringOstream);
const json::Array &SizesArray = *Array.getArray("sizes"); const json::Array &SizesArray = *Array.getArray("sizes");
if (RawStringOstream.str() != SizesArray[i].getAsString().value()) if (Buffer != SizesArray[i].getAsString().value())
return false; return false;
Buffer.clear(); Buffer.clear();
} }
// Check if key 'type' differs from the current one or is not valid. // Check if key 'type' differs from the current one or is not valid.
SAI->getElementType()->print(RawStringOstream); SAI->getElementType()->print(RawStringOstream);
if (RawStringOstream.str() != Array.getString("type").value()) { if (Buffer != Array.getString("type").value()) {
errs() << "Array has not a valid type.\n"; errs() << "Array has not a valid type.\n";
return false; return false;
} }