Skip to content

Commit d779685

Browse files
authored
[lldb] Nits on uses of llvm::raw_string_ostream (NFC) (llvm#108745)
As specified in the docs, 1) raw_string_ostream is always unbuffered and 2) the underlying buffer may be used directly ( 65b1361 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.
1 parent 4fdccd3 commit d779685

37 files changed

+35
-69
lines changed

lldb/include/lldb/Utility/Instrumentation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ template <typename... Ts> inline std::string stringify_args(const Ts &...ts) {
7070
std::string buffer;
7171
llvm::raw_string_ostream ss(buffer);
7272
stringify_helper(ss, ts...);
73-
return ss.str();
73+
return buffer;
7474
}
7575

7676
/// RAII object for instrumenting LLDB API functions.

lldb/source/Breakpoint/Breakpoint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ json::Value Breakpoint::GetStatistics() {
11271127
llvm::raw_string_ostream ss(buffer);
11281128
json::OStream json_os(ss);
11291129
bp_data_sp->Serialize(json_os);
1130-
if (auto expected_value = llvm::json::parse(ss.str())) {
1130+
if (auto expected_value = llvm::json::parse(buffer)) {
11311131
bp.try_emplace("details", std::move(*expected_value));
11321132
} else {
11331133
std::string details_error = toString(expected_value.takeError());

lldb/source/Commands/CommandObjectLog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class CommandObjectLogEnable : public CommandObjectParsed {
204204
channel, args.GetArgumentArrayRef(), log_file, m_options.log_options,
205205
m_options.buffer_size.GetCurrentValue(), m_options.handler,
206206
error_stream);
207-
result.GetErrorStream() << error_stream.str();
207+
result.GetErrorStream() << error;
208208

209209
if (success)
210210
result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -273,7 +273,7 @@ class CommandObjectLogDisable : public CommandObjectParsed {
273273
if (Log::DisableLogChannel(channel, args.GetArgumentArrayRef(),
274274
error_stream))
275275
result.SetStatus(eReturnStatusSuccessFinishNoResult);
276-
result.GetErrorStream() << error_stream.str();
276+
result.GetErrorStream() << error;
277277
}
278278
}
279279
};
@@ -313,7 +313,7 @@ class CommandObjectLogList : public CommandObjectParsed {
313313
if (success)
314314
result.SetStatus(eReturnStatusSuccessFinishResult);
315315
}
316-
result.GetOutputStream() << output_stream.str();
316+
result.GetOutputStream() << output;
317317
}
318318
};
319319
class CommandObjectLogDump : public CommandObjectParsed {
@@ -404,7 +404,7 @@ class CommandObjectLogDump : public CommandObjectParsed {
404404
result.SetStatus(eReturnStatusSuccessFinishNoResult);
405405
} else {
406406
result.SetStatus(eReturnStatusFailed);
407-
result.GetErrorStream() << error_stream.str();
407+
result.GetErrorStream() << error;
408408
}
409409
}
410410

lldb/source/Commands/CommandObjectRegexCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ llvm::Expected<std::string> CommandObjectRegexCommand::SubstituteVariables(
5151
output << part;
5252
}
5353

54-
return output.str();
54+
return buffer;
5555
}
5656

5757
void CommandObjectRegexCommand::DoExecute(llvm::StringRef command,

lldb/source/Core/Module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ uint32_t Module::Hash() {
16261626
const auto mtime = llvm::sys::toTimeT(m_object_mod_time);
16271627
if (mtime > 0)
16281628
id_strm << mtime;
1629-
return llvm::djbHash(id_strm.str());
1629+
return llvm::djbHash(identifier);
16301630
}
16311631

16321632
std::string Module::GetCacheKey() {
@@ -1636,7 +1636,7 @@ std::string Module::GetCacheKey() {
16361636
if (m_object_name)
16371637
strm << '(' << m_object_name << ')';
16381638
strm << '-' << llvm::format_hex(Hash(), 10);
1639-
return strm.str();
1639+
return key;
16401640
}
16411641

16421642
DataFileCache *Module::GetIndexCache() {

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
261261

262262
m_module->print(oss, nullptr);
263263

264-
oss.flush();
265-
266264
LLDB_LOGF(log, "Module being sent to JIT: \n%s", s.c_str());
267265
}
268266

lldb/source/Expression/IRInterpreter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static std::string PrintValue(const Value *value, bool truncate = false) {
4949
std::string s;
5050
raw_string_ostream rso(s);
5151
value->print(rso);
52-
rso.flush();
5352
if (truncate)
5453
s.resize(s.length() - 1);
5554

@@ -66,7 +65,6 @@ static std::string PrintType(const Type *type, bool truncate = false) {
6665
std::string s;
6766
raw_string_ostream rso(s);
6867
type->print(rso);
69-
rso.flush();
7068
if (truncate)
7169
s.resize(s.length() - 1);
7270
return s;
@@ -698,8 +696,6 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
698696

699697
module.print(oss, nullptr);
700698

701-
oss.flush();
702-
703699
LLDB_LOGF(log, "Module as passed in to IRInterpreter::Interpret: \n\"%s\"",
704700
s.c_str());
705701
}

lldb/source/Host/windows/PipeWindows.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ Status PipeWindows::CreateNew(bool child_process_inherit) {
7474
std::string pipe_name;
7575
llvm::raw_string_ostream pipe_name_stream(pipe_name);
7676
pipe_name_stream << "lldb.pipe." << ::GetCurrentProcessId() << "." << serial;
77-
pipe_name_stream.flush();
7877

7978
return CreateNew(pipe_name.c_str(), child_process_inherit);
8079
}

lldb/source/Interpreter/Options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ static std::string BuildShortOptions(const Option *long_options) {
923923
}
924924
}
925925
}
926-
return std::move(sstr.str());
926+
return storage;
927927
}
928928

929929
llvm::Expected<Args> Options::ParseAlias(const Args &args,

lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,6 @@ void DisassemblerLLVMC::MCDisasmInstance::PrintMCInst(
13661366
*m_subtarget_info_up, inst_stream);
13671367
m_instr_printer_up->setCommentStream(llvm::nulls());
13681368

1369-
comments_stream.flush();
1370-
13711369
static std::string g_newlines("\r\n");
13721370

13731371
for (size_t newline_pos = 0;

0 commit comments

Comments
 (0)