================
@@ -1891,6 +1893,12 @@ bool CommandInterpreter::HandleCommand(const char
*command_line,
m_transcript_stream << "(lldb) " << command_line << '\n';
+ // The same `transcript_item` will be used below to add output and error of
+ // the command.
+ auto transcript_item = std::make_shared<StructuredData::Dictionary>();
----------------
royitaqi wrote:
Two reasons for using the `shared_ptr`:
1. `m_transcript` holds a `shared_ptr` anyways. The
`m_transcript->AddItem(transcript_item)` call below this line also requires a
`shared_ptr`.
2. Many lines below this line, the `transcript_item` is used again in order to
add the command's output and error.
If we use `unique_ptr` instead, then the code will look like:
```
auto transcript_item = std::make_unique<StructuredData::Dictionary>();
transcript_item->AddStringItem("command", command_line);
m_transcript->AddItem(std::move(transcript_item));
...
auto last_transcript_item = m_transcript.last();
last_transcript_item->AddStringItem("output", result.GetOutputData());
last_transcript_item->AddStringItem("error", result.GetErrorData());
```
I feel the last part is weird (i.e. first creating `transcript_item` and move
into `m_transcript`, then getting it again from `m_transcript`). I feel a
`shared_ptr` is more readable and performant (since `m_transcript` holds a
`shared_ptr` anyways, rather than adding then getting).
WDYT?
https://github.com/llvm/llvm-project/pull/90703
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits