diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2019-02-11 23:13:08 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2019-02-11 23:13:08 +0000 |
commit | 796ac80b863ed92c3d8bcc296f678ff416afc8a8 (patch) | |
tree | 2d135344aad0612c190b08cf7fd218d98a2a368b /lldb/source/Interpreter | |
parent | 6cbc92915ae8f5cb1d5b265e15858e79c718e7ba (diff) | |
download | bcm5719-llvm-796ac80b863ed92c3d8bcc296f678ff416afc8a8.tar.gz bcm5719-llvm-796ac80b863ed92c3d8bcc296f678ff416afc8a8.zip |
Use std::make_shared in LLDB (NFC)
Unlike std::make_unique, which is only available since C++14,
std::make_shared is available since C++11. Not only is std::make_shared
a lot more readable compared to ::reset(new), it also performs a single
heap allocation for the object and control block.
Differential revision: https://reviews.llvm.org/D57990
llvm-svn: 353764
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 9 | ||||
-rw-r--r-- | lldb/source/Interpreter/Property.cpp | 55 |
2 files changed, 36 insertions, 28 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 45fb3a05ade..2ec59565438 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include <memory> #include <stdlib.h> #include <string> #include <vector> @@ -366,7 +367,7 @@ void CommandInterpreter::Initialize() { if (cmd_obj_sp) AddAlias("image", cmd_obj_sp); - alias_arguments_vector_sp.reset(new OptionArgVector); + alias_arguments_vector_sp = std::make_shared<OptionArgVector>(); cmd_obj_sp = GetCommandSPExact("expression", false); if (cmd_obj_sp) { @@ -392,7 +393,7 @@ void CommandInterpreter::Initialize() { cmd_obj_sp = GetCommandSPExact("process launch", false); if (cmd_obj_sp) { - alias_arguments_vector_sp.reset(new OptionArgVector); + alias_arguments_vector_sp = std::make_shared<OptionArgVector>(); #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) AddAlias("r", cmd_obj_sp, "--"); AddAlias("run", cmd_obj_sp, "--"); @@ -2967,7 +2968,7 @@ CommandInterpreter::GetIOHandler(bool force_create, flags = eHandleCommandFlagEchoCommand | eHandleCommandFlagPrintResult; } - m_command_io_handler_sp.reset(new IOHandlerEditline( + m_command_io_handler_sp = std::make_shared<IOHandlerEditline>( m_debugger, IOHandler::Type::CommandInterpreter, m_debugger.GetInputFile(), m_debugger.GetOutputFile(), m_debugger.GetErrorFile(), flags, "lldb", m_debugger.GetPrompt(), @@ -2975,7 +2976,7 @@ CommandInterpreter::GetIOHandler(bool force_create, false, // Don't enable multiple line input, just single line commands m_debugger.GetUseColor(), 0, // Don't show line numbers - *this)); + *this); } return m_command_io_handler_sp; } diff --git a/lldb/source/Interpreter/Property.cpp b/lldb/source/Interpreter/Property.cpp index 4cabc3fd2a6..eafa7afc1b1 100644 --- a/lldb/source/Interpreter/Property.cpp +++ b/lldb/source/Interpreter/Property.cpp @@ -15,6 +15,8 @@ #include "lldb/Interpreter/OptionValues.h" #include "lldb/Target/Language.h" +#include <memory> + using namespace lldb; using namespace lldb_private; @@ -29,18 +31,20 @@ Property::Property(const PropertyDefinition &definition) // "definition.default_uint_value" is not used // "definition.default_cstr_value" as a string value that represents the // default string value for the architecture/triple - m_value_sp.reset(new OptionValueArch(definition.default_cstr_value)); + m_value_sp = + std::make_shared<OptionValueArch>(definition.default_cstr_value); break; case OptionValue::eTypeArgs: // "definition.default_uint_value" is always a OptionValue::Type - m_value_sp.reset(new OptionValueArgs()); + m_value_sp = std::make_shared<OptionValueArgs>(); break; case OptionValue::eTypeArray: // "definition.default_uint_value" is always a OptionValue::Type - m_value_sp.reset(new OptionValueArray(OptionValue::ConvertTypeToMask( - (OptionValue::Type)definition.default_uint_value))); + m_value_sp = + std::make_shared<OptionValueArray>(OptionValue::ConvertTypeToMask( + (OptionValue::Type)definition.default_uint_value)); break; case OptionValue::eTypeBoolean: @@ -49,11 +53,12 @@ Property::Property(const PropertyDefinition &definition) // "definition.default_cstr_value" as a string value that represents the // default value. if (definition.default_cstr_value) - m_value_sp.reset(new OptionValueBoolean(OptionArgParser::ToBoolean( - llvm::StringRef(definition.default_cstr_value), false, nullptr))); + m_value_sp = + std::make_shared<OptionValueBoolean>(OptionArgParser::ToBoolean( + llvm::StringRef(definition.default_cstr_value), false, nullptr)); else - m_value_sp.reset( - new OptionValueBoolean(definition.default_uint_value != 0)); + m_value_sp = std::make_shared<OptionValueBoolean>( + definition.default_uint_value != 0); break; case OptionValue::eTypeChar: { @@ -64,8 +69,9 @@ Property::Property(const PropertyDefinition &definition) } case OptionValue::eTypeDictionary: // "definition.default_uint_value" is always a OptionValue::Type - m_value_sp.reset(new OptionValueDictionary(OptionValue::ConvertTypeToMask( - (OptionValue::Type)definition.default_uint_value))); + m_value_sp = + std::make_shared<OptionValueDictionary>(OptionValue::ConvertTypeToMask( + (OptionValue::Type)definition.default_uint_value)); break; case OptionValue::eTypeEnum: @@ -100,14 +106,14 @@ Property::Property(const PropertyDefinition &definition) FileSpec file_spec = FileSpec(definition.default_cstr_value); if (resolve) FileSystem::Instance().Resolve(file_spec); - m_value_sp.reset(new OptionValueFileSpec(file_spec, resolve)); + m_value_sp = std::make_shared<OptionValueFileSpec>(file_spec, resolve); break; } case OptionValue::eTypeFileSpecList: // "definition.default_uint_value" is not used for a // OptionValue::eTypeFileSpecList - m_value_sp.reset(new OptionValueFileSpecList()); + m_value_sp = std::make_shared<OptionValueFileSpecList>(); break; case OptionValue::eTypeFormat: @@ -122,7 +128,7 @@ Property::Property(const PropertyDefinition &definition) nullptr); else new_format = (Format)definition.default_uint_value; - m_value_sp.reset(new OptionValueFormat(new_format)); + m_value_sp = std::make_shared<OptionValueFormat>(new_format); } break; @@ -138,29 +144,30 @@ Property::Property(const PropertyDefinition &definition) llvm::StringRef(definition.default_cstr_value)); else new_lang = (LanguageType)definition.default_uint_value; - m_value_sp.reset(new OptionValueLanguage(new_lang)); + m_value_sp = std::make_shared<OptionValueLanguage>(new_lang); } break; case OptionValue::eTypeFormatEntity: // "definition.default_cstr_value" as a string value that represents the // default - m_value_sp.reset( - new OptionValueFormatEntity(definition.default_cstr_value)); + m_value_sp = std::make_shared<OptionValueFormatEntity>( + definition.default_cstr_value); break; case OptionValue::eTypePathMap: // "definition.default_uint_value" tells us if notifications should occur // for path mappings - m_value_sp.reset( - new OptionValuePathMappings(definition.default_uint_value != 0)); + m_value_sp = std::make_shared<OptionValuePathMappings>( + definition.default_uint_value != 0); break; case OptionValue::eTypeRegex: // "definition.default_uint_value" is used to the regular expression flags // "definition.default_cstr_value" the default regular expression value // value. - m_value_sp.reset(new OptionValueRegex(definition.default_cstr_value)); + m_value_sp = + std::make_shared<OptionValueRegex>(definition.default_cstr_value); break; case OptionValue::eTypeSInt64: @@ -168,10 +175,10 @@ Property::Property(const PropertyDefinition &definition) // "definition.default_cstr_value" is NULL, otherwise interpret // "definition.default_cstr_value" as a string value that represents the // default value. - m_value_sp.reset(new OptionValueSInt64( + m_value_sp = std::make_shared<OptionValueSInt64>( definition.default_cstr_value ? StringConvert::ToSInt64(definition.default_cstr_value) - : definition.default_uint_value)); + : definition.default_uint_value); break; case OptionValue::eTypeUInt64: @@ -179,10 +186,10 @@ Property::Property(const PropertyDefinition &definition) // "definition.default_cstr_value" is NULL, otherwise interpret // "definition.default_cstr_value" as a string value that represents the // default value. - m_value_sp.reset(new OptionValueUInt64( + m_value_sp = std::make_shared<OptionValueUInt64>( definition.default_cstr_value ? StringConvert::ToUInt64(definition.default_cstr_value) - : definition.default_uint_value)); + : definition.default_uint_value); break; case OptionValue::eTypeUUID: @@ -192,7 +199,7 @@ Property::Property(const PropertyDefinition &definition) UUID uuid; if (definition.default_cstr_value) uuid.SetFromStringRef(definition.default_cstr_value); - m_value_sp.reset(new OptionValueUUID(uuid)); + m_value_sp = std::make_shared<OptionValueUUID>(uuid); } break; |