Use index, not value, when removing items from wxDataViewTreeNode

This avoids another (linear) search among the item siblings, as we can
use the index we've just found instead directly.
This commit is contained in:
Vadim Zeitlin
2017-12-17 17:31:09 +01:00
parent 0268c062c0
commit 259a357824

View File

@@ -471,10 +471,10 @@ public:
void InsertChild(wxDataViewTreeNode *node, unsigned index); void InsertChild(wxDataViewTreeNode *node, unsigned index);
void RemoveChild(wxDataViewTreeNode *node) void RemoveChild(unsigned index)
{ {
wxCHECK_RET( m_branchData != NULL, "leaf node doesn't have children" ); wxCHECK_RET( m_branchData != NULL, "leaf node doesn't have children" );
m_branchData->children.Remove(node); m_branchData->children.RemoveAt(index);
} }
// returns position of child node for given item in children list or wxNOT_FOUND // returns position of child node for given item in children list or wxNOT_FOUND
@@ -2835,7 +2835,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
// Delete the item from wxDataViewTreeNode representation: // Delete the item from wxDataViewTreeNode representation:
const int itemsDeleted = 1 + itemNode->GetSubTreeCount(); const int itemsDeleted = 1 + itemNode->GetSubTreeCount();
parentNode->RemoveChild(itemNode); parentNode->RemoveChild(itemPosInNode);
delete itemNode; delete itemNode;
parentNode->ChangeSubTreeCount(-itemsDeleted); parentNode->ChangeSubTreeCount(-itemsDeleted);