Author: enrico Date: Mon Dec 21 17:10:17 2015 New Revision: 256212 URL: http://llvm.org/viewvc/llvm-project?rev=256212&view=rev Log: Reduce code duplication
Modified: lldb/trunk/source/Core/ValueObject.cpp Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=256212&r1=256211&r2=256212&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Mon Dec 21 17:10:17 2015 @@ -601,40 +601,16 @@ ValueObjectSP ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs, size_t* index_of_error) { - if (idxs.size() == 0) - return GetSP(); - ValueObjectSP root(GetSP()); - for (size_t idx : idxs) - { - root = root->GetChildAtIndex(idx, true); - if (!root) - { - if (index_of_error) - *index_of_error = idx; - return root; - } - } - return root; + return GetChildAtIndexPath( std::vector<size_t>(idxs), + index_of_error ); } ValueObjectSP ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs, size_t* index_of_error) { - if (idxs.size() == 0) - return GetSP(); - ValueObjectSP root(GetSP()); - for (std::pair<size_t, bool> idx : idxs) - { - root = root->GetChildAtIndex(idx.first, idx.second); - if (!root) - { - if (index_of_error) - *index_of_error = idx.first; - return root; - } - } - return root; + return GetChildAtIndexPath( std::vector<std::pair<size_t,bool>>(idxs), + index_of_error ); } lldb::ValueObjectSP @@ -681,20 +657,16 @@ lldb::ValueObjectSP ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names, ConstString* name_of_error) { - if (names.size() == 0) - return GetSP(); - ValueObjectSP root(GetSP()); - for (ConstString name : names) - { - root = root->GetChildMemberWithName(name, true); - if (!root) - { - if (name_of_error) - *name_of_error = name; - return root; - } - } - return root; + return GetChildAtNamePath( std::vector<ConstString>(names), + name_of_error ); +} + +lldb::ValueObjectSP +ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names, + ConstString* name_of_error) +{ + return GetChildAtNamePath( std::vector<std::pair<ConstString,bool>>(names), + name_of_error ); } lldb::ValueObjectSP @@ -718,7 +690,7 @@ ValueObject::GetChildAtNamePath (const s } lldb::ValueObjectSP -ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names, +ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names, ConstString* name_of_error) { if (names.size() == 0) @@ -731,32 +703,12 @@ ValueObject::GetChildAtNamePath (const s { if (name_of_error) *name_of_error = name.first; - return root; + return root; } } return root; } -lldb::ValueObjectSP -ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names, - ConstString* name_of_error) -{ - if (names.size() == 0) - return GetSP(); - ValueObjectSP root(GetSP()); - for (std::pair<ConstString, bool> name : names) - { - root = root->GetChildMemberWithName(name.first, name.second); - if (!root) - { - if (name_of_error) - *name_of_error = name.first; - return root; - } - } - return root; -} - size_t ValueObject::GetIndexOfChildWithName (const ConstString &name) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits