aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectCommands.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2025-07-25 15:55:21 -0700
committerGitHub <noreply@github.com>2025-07-25 15:55:21 -0700
commitcf6a4bbc42c7e54bf6e251206134b207e757b604 (patch)
tree2f03b5614fbb26d189c6a68274b4f48d0fcac931 /lldb/source/Commands/CommandObjectCommands.cpp
parent67b519577ee6b3743c6c03c6230991cede5648a5 (diff)
downloadllvm-cf6a4bbc42c7e54bf6e251206134b207e757b604.zip
llvm-cf6a4bbc42c7e54bf6e251206134b207e757b604.tar.gz
llvm-cf6a4bbc42c7e54bf6e251206134b207e757b604.tar.bz2
[lldb] Use std::make_shared where possible (NFC) (#150714)
This is a continuation of 68fd102, which did the same thing but only for StopInfo. Using make_shared is both safer and more efficient: - With make_shared, the object and the control block are allocated together, which is more efficient. - With make_shared, the enable_shared_from_this base class is properly linked to the control block before the constructor finishes, so shared_from_this() will be safe to use (though still not recommended during construction).
Diffstat (limited to 'lldb/source/Commands/CommandObjectCommands.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectCommands.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index 10dc273..3049eb8 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -25,6 +25,7 @@
#include "lldb/Utility/Args.h"
#include "lldb/Utility/StringList.h"
#include "llvm/ADT/StringRef.h"
+#include <memory>
#include <optional>
using namespace lldb;
@@ -467,7 +468,7 @@ protected:
// Verify & handle any options/arguments passed to the alias command
OptionArgVectorSP option_arg_vector_sp =
- OptionArgVectorSP(new OptionArgVector);
+ std::make_shared<OptionArgVector>();
const bool include_aliases = true;
// Look up the command using command's name first. This is to resolve
@@ -543,7 +544,7 @@ protected:
CommandObject *cmd_obj = command_obj_sp.get();
CommandObject *sub_cmd_obj = nullptr;
OptionArgVectorSP option_arg_vector_sp =
- OptionArgVectorSP(new OptionArgVector);
+ std::make_shared<OptionArgVector>();
while (cmd_obj->IsMultiwordObject() && !args.empty()) {
auto sub_command = args[0].ref();
@@ -2504,9 +2505,9 @@ protected:
CommandObjectSP new_cmd_sp;
if (m_options.m_class_name.empty()) {
- new_cmd_sp.reset(new CommandObjectPythonFunction(
+ new_cmd_sp = std::make_shared<CommandObjectPythonFunction>(
m_interpreter, m_cmd_name, m_options.m_funct_name,
- m_options.m_short_help, m_synchronicity, m_completion_type));
+ m_options.m_short_help, m_synchronicity, m_completion_type);
} else {
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (!interpreter) {
@@ -2528,9 +2529,9 @@ protected:
if (!result.Succeeded())
return;
} else
- new_cmd_sp.reset(new CommandObjectScriptingObjectRaw(
+ new_cmd_sp = std::make_shared<CommandObjectScriptingObjectRaw>(
m_interpreter, m_cmd_name, cmd_obj_sp, m_synchronicity,
- m_completion_type));
+ m_completion_type);
}
// Assume we're going to succeed...