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/Commands | |
parent | 6cbc92915ae8f5cb1d5b265e15858e79c718e7ba (diff) | |
download | llvm-796ac80b863ed92c3d8bcc296f678ff416afc8a8.zip llvm-796ac80b863ed92c3d8bcc296f678ff416afc8a8.tar.gz llvm-796ac80b863ed92c3d8bcc296f678ff416afc8a8.tar.bz2 |
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/Commands')
-rw-r--r-- | lldb/source/Commands/CommandObjectBreakpoint.cpp | 7 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectFrame.cpp | 10 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectMemory.cpp | 15 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectType.cpp | 33 |
4 files changed, 35 insertions, 30 deletions
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index 3996bcf..b9b0cb5 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -6,8 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <vector> - #include "CommandObjectBreakpoint.h" #include "CommandObjectBreakpointCommand.h" #include "lldb/Breakpoint/Breakpoint.h" @@ -30,6 +28,9 @@ #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/StreamString.h" +#include <memory> +#include <vector> + using namespace lldb; using namespace lldb_private; @@ -615,7 +616,7 @@ public: m_move_to_nearest_code = eLazyBoolCalculate; m_source_regex_func_names.clear(); m_python_class.clear(); - m_extra_args_sp.reset(new StructuredData::Dictionary()); + m_extra_args_sp = std::make_shared<StructuredData::Dictionary>(); m_current_key.clear(); } diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index 17a0896..3b4259b 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -5,9 +5,6 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// - -#include <string> - #include "CommandObjectFrame.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" @@ -45,6 +42,9 @@ #include "lldb/Utility/StreamString.h" #include "lldb/Utility/Timer.h" +#include <memory> +#include <string> + using namespace lldb; using namespace lldb_private; @@ -526,9 +526,9 @@ protected: ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp); else if (!m_option_variable.summary_string.IsCurrentValueEmpty()) - summary_format_sp.reset(new StringSummaryFormat( + summary_format_sp = std::make_shared<StringSummaryFormat>( TypeSummaryImpl::Flags(), - m_option_variable.summary_string.GetCurrentValue())); + m_option_variable.summary_string.GetCurrentValue()); DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions( eLanguageRuntimeDescriptionDisplayVerbosityFull, eFormatDefault, diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 439f475..1f4a369 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -6,8 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <inttypes.h> - #include "clang/AST/Decl.h" #include "CommandObjectMemory.h" @@ -42,6 +40,9 @@ #include "lldb/lldb-private.h" +#include <cinttypes> +#include <memory> + using namespace lldb; using namespace lldb_private; @@ -652,7 +653,7 @@ protected: addr = addr + (*size * m_memory_options.m_offset.GetCurrentValue()); } else if (m_format_options.GetFormatValue().GetCurrentValue() != eFormatCString) { - data_sp.reset(new DataBufferHeap(total_byte_size, '\0')); + data_sp = std::make_shared<DataBufferHeap>(total_byte_size, '\0'); if (data_sp->GetBytes() == nullptr) { result.AppendErrorWithFormat( "can't allocate 0x%" PRIx32 @@ -692,8 +693,9 @@ protected: item_byte_size = target->GetMaximumSizeOfStringSummary(); if (!m_format_options.GetCountValue().OptionWasSet()) item_count = 1; - data_sp.reset(new DataBufferHeap((item_byte_size + 1) * item_count, - '\0')); // account for NULLs as necessary + data_sp = std::make_shared<DataBufferHeap>( + (item_byte_size + 1) * item_count, + '\0'); // account for NULLs as necessary if (data_sp->GetBytes() == nullptr) { result.AppendErrorWithFormat( "can't allocate 0x%" PRIx64 @@ -740,7 +742,8 @@ protected: if (break_on_no_NULL) break; } - data_sp.reset(new DataBufferHeap(data_sp->GetBytes(), bytes_read + 1)); + data_sp = + std::make_shared<DataBufferHeap>(data_sp->GetBytes(), bytes_read + 1); } m_next_addr = addr + bytes_read; diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index 8241615..64ed459 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -8,10 +8,6 @@ #include "CommandObjectType.h" -#include <algorithm> -#include <cctype> -#include <functional> - #include "lldb/Core/Debugger.h" #include "lldb/Core/IOHandler.h" #include "lldb/DataFormatters/DataVisualization.h" @@ -39,6 +35,11 @@ #include "llvm/ADT/STLExtras.h" +#include <algorithm> +#include <cctype> +#include <functional> +#include <memory> + using namespace lldb; using namespace lldb_private; @@ -205,9 +206,9 @@ public: // for every type in the list TypeSummaryImplSP script_format; - script_format.reset(new ScriptSummaryFormat( + script_format = std::make_shared<ScriptSummaryFormat>( options->m_flags, funct_name_str.c_str(), - lines.CopyList(" ").c_str())); + lines.CopyList(" ").c_str()); Status error; @@ -449,12 +450,12 @@ protected: // class SyntheticChildrenSP synth_provider; - synth_provider.reset(new ScriptedSyntheticChildren( + synth_provider = std::make_shared<ScriptedSyntheticChildren>( SyntheticChildren::Flags() .SetCascades(options->m_cascade) .SetSkipPointers(options->m_skip_pointers) .SetSkipReferences(options->m_skip_references), - class_name_str.c_str())); + class_name_str.c_str()); lldb::TypeCategoryImplSP category; DataVisualization::Categories::GetCategory( @@ -699,18 +700,18 @@ protected: TypeFormatImplSP entry; if (m_command_options.m_custom_type_name.empty()) - entry.reset(new TypeFormatImpl_Format( + entry = std::make_shared<TypeFormatImpl_Format>( format, TypeFormatImpl::Flags() .SetCascades(m_command_options.m_cascade) .SetSkipPointers(m_command_options.m_skip_pointers) - .SetSkipReferences(m_command_options.m_skip_references))); + .SetSkipReferences(m_command_options.m_skip_references)); else - entry.reset(new TypeFormatImpl_EnumType( + entry = std::make_shared<TypeFormatImpl_EnumType>( ConstString(m_command_options.m_custom_type_name.c_str()), TypeFormatImpl::Flags() .SetCascades(m_command_options.m_cascade) .SetSkipPointers(m_command_options.m_skip_pointers) - .SetSkipReferences(m_command_options.m_skip_references))); + .SetSkipReferences(m_command_options.m_skip_references)); // now I have a valid format, let's add it to every type @@ -1352,8 +1353,8 @@ bool CommandObjectTypeSummaryAdd::Execute_ScriptSummary( std::string code = (" " + m_options.m_python_function + "(valobj,internal_dict)"); - script_format.reset( - new ScriptSummaryFormat(m_options.m_flags, funct_name, code.c_str())); + script_format = std::make_shared<ScriptSummaryFormat>( + m_options.m_flags, funct_name, code.c_str()); ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter(); @@ -1389,8 +1390,8 @@ bool CommandObjectTypeSummaryAdd::Execute_ScriptSummary( std::string code = " " + m_options.m_python_script; - script_format.reset(new ScriptSummaryFormat( - m_options.m_flags, funct_name_str.c_str(), code.c_str())); + script_format = std::make_shared<ScriptSummaryFormat>( + m_options.m_flags, funct_name_str.c_str(), code.c_str()); } else { // Use an IOHandler to grab Python code from the user ScriptAddOptions *options = |