Simplify sort order handling for first child item

Test whether this is the first child before testing whether the branch
is open as this allows to avoid the special case of inserting the first
child under the root node and simplifies the assert condition to a
simple check that the sort order is already what we expect.
This commit is contained in:
Vadim Zeitlin
2017-12-17 19:09:04 +01:00
parent 3f41e84830
commit 1bfe42b0ce

View File

@@ -1694,26 +1694,16 @@ void wxDataViewTreeNode::InsertChild(wxDataViewTreeNode *node, unsigned index)
// child list to lose the current sort order, if any. // child list to lose the current sort order, if any.
m_branchData->sortOrder = SortOrder(); m_branchData->sortOrder = SortOrder();
} }
else if ( m_branchData->open ) else if ( m_branchData->children.empty() )
{ {
// For open branches, children should be already sorted, with one if ( m_branchData->open )
// possible exception that we check for here:
if ( m_branchData->sortOrder != sortOrder )
{ {
// This can happen for the root node, on the first child addition, // We don't need to search for the right place to insert the first
// in which case the children are nevertheless sorted (because // item (there is only one), but we do need to remember the sort
// there is only one of them), but we need to set the correct sort // order to use for the subsequent ones.
// order.
wxASSERT_MSG( !m_parent && m_branchData->children.empty(),
"Logic error in wxDVC sorting code" );
m_branchData->sortOrder = sortOrder; m_branchData->sortOrder = sortOrder;
} }
else
// We can use fast insertion.
insertSorted = true;
}
else if ( m_branchData->children.empty() )
{ {
// We're inserting the first child of a closed node. We can choose // We're inserting the first child of a closed node. We can choose
// whether to consider this empty child list sorted or unsorted. // whether to consider this empty child list sorted or unsorted.
@@ -1721,6 +1711,16 @@ void wxDataViewTreeNode::InsertChild(wxDataViewTreeNode *node, unsigned index)
// node is opened in the view, which may be never. // node is opened in the view, which may be never.
m_branchData->sortOrder = SortOrder(); m_branchData->sortOrder = SortOrder();
} }
}
else if ( m_branchData->open )
{
// For open branches, children should be already sorted.
wxASSERT_MSG( m_branchData->sortOrder == sortOrder,
wxS("Logic error in wxDVC sorting code") );
// We can use fast insertion.
insertSorted = true;
}
else if ( m_branchData->sortOrder == sortOrder ) else if ( m_branchData->sortOrder == sortOrder )
{ {
// The children are already sorted by the correct criteria (because // The children are already sorted by the correct criteria (because
@@ -1731,8 +1731,8 @@ void wxDataViewTreeNode::InsertChild(wxDataViewTreeNode *node, unsigned index)
} }
else else
{ {
// The children aren't sorted by the correct criteria, so we just // The children of this closed node aren't sorted by the correct
// insert unsorted. // criteria, so we just insert unsorted.
m_branchData->sortOrder = SortOrder(); m_branchData->sortOrder = SortOrder();
} }