From 614717388cfccd6a6d34ed17a4680181e22cab22 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Thu, 26 Jun 2014 00:00:48 +0000 Subject: Introduce a string_ostream string builder facilty string_ostream is a safe and efficient string builder that combines opaque stack storage with a built-in ostream interface. small_string_ostream additionally permits an explicit stack storage size other than the default 128 bytes to be provided. Beyond that, storage is transferred to the heap. This convenient class can be used in most places an std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair would previously have been used, in order to guarantee consistent access without byte truncation. The patch also converts much of LLVM to use the new facility. These changes include several probable bug fixes for truncated output, a programming error that's no longer possible with the new interface. llvm-svn: 211749 --- llvm/lib/CodeGen/MachineBlockPlacement.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'llvm/lib/CodeGen/MachineBlockPlacement.cpp') diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index 74af1e2d64b..891f605e2a1 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -264,23 +264,19 @@ INITIALIZE_PASS_END(MachineBlockPlacement, "block-placement2", /// /// Only used by debug logging. static std::string getBlockName(MachineBasicBlock *BB) { - std::string Result; - raw_string_ostream OS(Result); + string_ostream OS; OS << "BB#" << BB->getNumber() << " (derived from LLVM BB '" << BB->getName() << "')"; - OS.flush(); - return Result; + return OS.str(); } /// \brief Helper to print the number of a MBB. /// /// Only used by debug logging. static std::string getBlockNum(MachineBasicBlock *BB) { - std::string Result; - raw_string_ostream OS(Result); + string_ostream OS; OS << "BB#" << BB->getNumber(); - OS.flush(); - return Result; + return OS.str(); } #endif -- cgit v1.2.3