[Lldb-commits] [lldb] r140808 - in /lldb/trunk: include/lldb/Symbol/Block.h source/Symbol/Block.cpp
Greg Clayton
gclayton at apple.com
Thu Sep 29 14:19:26 PDT 2011
Author: gclayton
Date: Thu Sep 29 16:19:25 2011
New Revision: 140808
URL: http://llvm.org/viewvc/llvm-project?rev=140808&view=rev
Log:
Free up some space in lldb_private::Block by not requiring a sibling pointer.
The old way of storing blocks used to use the sibling pointer, but now all
blocks contain a collection of shared pointers to blocks so this isn't required
anymore and a parent can be asked to find the sibling block for a child block.
Modified:
lldb/trunk/include/lldb/Symbol/Block.h
lldb/trunk/source/Symbol/Block.cpp
Modified: lldb/trunk/include/lldb/Symbol/Block.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Block.h?rev=140808&r1=140807&r2=140808&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Block.h (original)
+++ lldb/trunk/include/lldb/Symbol/Block.h Thu Sep 29 16:19:25 2011
@@ -247,10 +247,7 @@
/// sibling.
//------------------------------------------------------------------
Block *
- GetSibling () const
- {
- return m_sibling;
- }
+ GetSibling () const;
//------------------------------------------------------------------
/// Get the first child block.
@@ -398,12 +395,6 @@
m_parent_scope = parent_scope;
}
- void
- SetSibling (Block *block)
- {
- m_sibling = block;
- }
-
//------------------------------------------------------------------
/// Set accessor for the variable list.
///
@@ -466,7 +457,6 @@
// Member variables.
//------------------------------------------------------------------
SymbolContextScope *m_parent_scope;
- Block *m_sibling;
collection m_children;
VMRange::collection m_ranges; ///< A list of address offset ranges relative to the function's section/offset address.
lldb::InlineFunctionInfoSP m_inlineInfoSP; ///< Inlined function information.
@@ -475,6 +465,11 @@
m_parsed_block_variables:1,
m_parsed_child_blocks:1;
+ // A parent of child blocks can be asked to find a sibling block given
+ // one of its child blocks
+ Block *
+ GetSiblingForChild (const Block *child_block) const;
+
private:
DISALLOW_COPY_AND_ASSIGN (Block);
};
Modified: lldb/trunk/source/Symbol/Block.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Block.cpp?rev=140808&r1=140807&r2=140808&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Block.cpp (original)
+++ lldb/trunk/source/Symbol/Block.cpp Thu Sep 29 16:19:25 2011
@@ -21,7 +21,6 @@
Block::Block(lldb::user_id_t uid) :
UserID(uid),
m_parent_scope (NULL),
- m_sibling (NULL),
m_children (),
m_ranges (),
m_inlineInfoSP (),
@@ -117,10 +116,9 @@
m_variable_list_sp->Dump(s, show_context);
}
- for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling())
- {
- child_block->Dump(s, base_addr, depth - 1, show_context);
- }
+ collection::const_iterator pos, end = m_children.end();
+ for (pos = m_children.begin(); pos != end; ++pos)
+ (*pos)->Dump(s, base_addr, depth - 1, show_context);
s->IndentLess();
}
@@ -135,9 +133,10 @@
return this;
Block *matching_block = NULL;
- for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling())
+ collection::const_iterator pos, end = m_children.end();
+ for (pos = m_children.begin(); pos != end; ++pos)
{
- matching_block = child_block->FindBlockByID (block_id);
+ matching_block = (*pos)->FindBlockByID (block_id);
if (matching_block)
break;
}
@@ -458,16 +457,8 @@
{
if (child_block_sp)
{
- Block *block_needs_sibling = NULL;
-
- if (!m_children.empty())
- block_needs_sibling = m_children.back().get();
-
child_block_sp->SetParentScope (this);
m_children.push_back (child_block_sp);
-
- if (block_needs_sibling)
- block_needs_sibling->SetSibling (child_block_sp.get());
}
}
@@ -512,10 +503,10 @@
if (get_child_block_variables)
{
- for (Block *child_block = GetFirstChild();
- child_block != NULL;
- child_block = child_block->GetSibling())
- {
+ collection::const_iterator pos, end = m_children.end();
+ for (pos = m_children.begin(); pos != end; ++pos)
+ {
+ Block *child_block = pos->get();
if (stop_if_child_block_is_inlined_function == false ||
child_block->GetInlinedFunctionInfo() == NULL)
{
@@ -590,8 +581,9 @@
if (set_children)
{
m_parsed_child_blocks = true;
- for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling())
- child_block->SetBlockInfoHasBeenParsed (b, true);
+ collection::const_iterator pos, end = m_children.end();
+ for (pos = m_children.begin(); pos != end; ++pos)
+ (*pos)->SetBlockInfoHasBeenParsed (b, true);
}
}
@@ -601,8 +593,42 @@
m_parsed_block_variables = b;
if (set_children)
{
- for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling())
- child_block->SetDidParseVariables (b, true);
+ collection::const_iterator pos, end = m_children.end();
+ for (pos = m_children.begin(); pos != end; ++pos)
+ (*pos)->SetDidParseVariables (b, true);
+ }
+}
+
+
+Block *
+Block::GetSibling() const
+{
+ if (m_parent_scope)
+ {
+ Block *parent_block = m_parent_scope->CalculateSymbolContextBlock();
+ if (parent_block)
+ return parent_block->GetSiblingForChild (this);
}
+ return NULL;
+}
+// A parent of child blocks can be asked to find a sibling block given
+// one of its child blocks
+Block *
+Block::GetSiblingForChild (const Block *child_block) const
+{
+ if (!m_children.empty())
+ {
+ collection::const_iterator pos, end = m_children.end();
+ for (pos = m_children.begin(); pos != end; ++pos)
+ {
+ if (pos->get() == child_block)
+ {
+ if (++pos != end)
+ return pos->get();
+ break;
+ }
+ }
+ }
+ return NULL;
}
More information about the lldb-commits
mailing list