Author: Pavel Labath Date: 2020-07-08T17:42:47+02:00 New Revision: 7fd29699d6042af674c4f4ad185c91f82cb73b52
URL: https://github.com/llvm/llvm-project/commit/7fd29699d6042af674c4f4ad185c91f82cb73b52 DIFF: https://github.com/llvm/llvm-project/commit/7fd29699d6042af674c4f4ad185c91f82cb73b52.diff LOG: [lldb] Modernize/clean up ValueObject::GetChildMemberWithName Added: Modified: lldb/source/Core/ValueObject.cpp Removed: ################################################################################ diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index e6fad3ada5f0..f13ad63dfb61 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -574,15 +574,13 @@ size_t ValueObject::GetIndexOfChildWithName(ConstString name) { ValueObjectSP ValueObject::GetChildMemberWithName(ConstString name, bool can_create) { - // when getting a child by name, it could be buried inside some base classes - // (which really aren't part of the expression path), so we need a vector of - // indexes that can get us down to the correct child - ValueObjectSP child_sp; - - // We may need to update our value if we are dynamic + // We may need to update our value if we are dynamic. if (IsPossibleDynamicType()) UpdateValueIfNeeded(false); + // When getting a child by name, it could be buried inside some base classes + // (which really aren't part of the expression path), so we need a vector of + // indexes that can get us down to the correct child. std::vector<uint32_t> child_indexes; bool omit_empty_base_classes = true; @@ -592,20 +590,13 @@ ValueObjectSP ValueObject::GetChildMemberWithName(ConstString name, const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName( name.GetCString(), omit_empty_base_classes, child_indexes); - if (num_child_indexes > 0) { - std::vector<uint32_t>::const_iterator pos = child_indexes.begin(); - std::vector<uint32_t>::const_iterator end = child_indexes.end(); - - child_sp = GetChildAtIndex(*pos, can_create); - for (++pos; pos != end; ++pos) { - if (child_sp) { - ValueObjectSP new_child_sp(child_sp->GetChildAtIndex(*pos, can_create)); - child_sp = new_child_sp; - } else { - child_sp.reset(); - } - } - } + if (num_child_indexes == 0) + return nullptr; + + ValueObjectSP child_sp = GetSP(); + for (uint32_t idx : child_indexes) + if (child_sp) + child_sp = child_sp->GetChildAtIndex(idx, can_create); return child_sp; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits