Patch from Bo to speed up FindNode() in internal data tree structure (GTK)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47697 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
#include "wx/calctrl.h"
|
#include "wx/calctrl.h"
|
||||||
#include "wx/popupwin.h"
|
#include "wx/popupwin.h"
|
||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
|
#include "wx/list.h"
|
||||||
|
#include "wx/listimpl.cpp"
|
||||||
|
|
||||||
|
|
||||||
#include "wx/gtk/private.h"
|
#include "wx/gtk/private.h"
|
||||||
@@ -53,6 +55,9 @@ typedef struct _GtkWxTreeModel GtkWxTreeModel;
|
|||||||
// wxDataViewCtrlInternal
|
// wxDataViewCtrlInternal
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
WX_DECLARE_LIST(wxDataViewItem, ItemList);
|
||||||
|
WX_DEFINE_LIST(ItemList);
|
||||||
|
|
||||||
class wxDataViewCtrlInternal
|
class wxDataViewCtrlInternal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -2432,6 +2437,9 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
|||||||
g_model = m_wx_model;
|
g_model = m_wx_model;
|
||||||
|
|
||||||
wxGtkTreeModelNode *parent = FindParentNode( iter );
|
wxGtkTreeModelNode *parent = FindParentNode( iter );
|
||||||
|
if( parent == NULL )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
unsigned int pos = parent->GetChildren().Index( iter->user_data );
|
unsigned int pos = parent->GetChildren().Index( iter->user_data );
|
||||||
|
|
||||||
if (pos == parent->GetChildCount()-1)
|
if (pos == parent->GetChildCount()-1)
|
||||||
@@ -2534,30 +2542,48 @@ gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
static wxGtkTreeModelNode*
|
static wxGtkTreeModelNode*
|
||||||
wxDataViewCtrlInternal_FindNode( wxGtkTreeModelNode *node, const wxDataViewItem &item )
|
wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
|
||||||
{
|
{
|
||||||
if (!node) return NULL;
|
if( model == NULL )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
size_t count = node->GetNodesCount();
|
ItemList list;
|
||||||
size_t i;
|
list.DeleteContents( true );
|
||||||
for (i = 0; i < count; i++)
|
wxDataViewItem it( item );
|
||||||
|
while( it.IsOk() )
|
||||||
{
|
{
|
||||||
wxGtkTreeModelNode *child = node->GetNodes().Item( i );
|
wxDataViewItem * pItem = new wxDataViewItem( it );
|
||||||
if (child->GetItem().GetID() == item.GetID())
|
list.Insert( pItem );
|
||||||
{
|
it = model->GetParent( it );
|
||||||
// wxPrintf( "leave findnode at %d\n", i );
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxGtkTreeModelNode *node2 = wxDataViewCtrlInternal_FindNode( child, item );
|
|
||||||
if (node2)
|
|
||||||
{
|
|
||||||
// wxPrintf( "branch findnode at %d\n", i );
|
|
||||||
return node2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
wxGtkTreeModelNode * node = treeNode;
|
||||||
|
for( ItemList::Node * n = list.GetFirst(); n; n = n->GetNext() )
|
||||||
|
{
|
||||||
|
if( node && node->GetNodes().GetCount() != 0 )
|
||||||
|
{
|
||||||
|
int len = node->GetNodes().GetCount();
|
||||||
|
wxGtkTreeModelNodes nodes = node->GetNodes();
|
||||||
|
int j = 0;
|
||||||
|
for( ; j < len; j ++)
|
||||||
|
{
|
||||||
|
if( nodes[j]->GetItem() == *(n->GetData()))
|
||||||
|
{
|
||||||
|
node = nodes[j];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( j == len )
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
|
wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
|
||||||
@@ -2569,7 +2595,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
|
|||||||
if (!item.IsOk())
|
if (!item.IsOk())
|
||||||
return m_root;
|
return m_root;
|
||||||
|
|
||||||
wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_root, item );
|
wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@@ -2586,7 +2612,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item
|
|||||||
if (!item.IsOk())
|
if (!item.IsOk())
|
||||||
return m_root;
|
return m_root;
|
||||||
|
|
||||||
wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_root, item );
|
wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@@ -2599,31 +2625,56 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item
|
|||||||
}
|
}
|
||||||
|
|
||||||
static wxGtkTreeModelNode*
|
static wxGtkTreeModelNode*
|
||||||
wxDataViewCtrlInternal_FindParentNode( wxGtkTreeModelNode *node, const wxDataViewItem &item )
|
wxDataViewCtrlInternal_FindParentNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
|
||||||
{
|
{
|
||||||
size_t child_count = node->GetChildCount();
|
if( model == NULL )
|
||||||
void *id = item.GetID();
|
return NULL;
|
||||||
const wxGtkTreeModelChildren &children = node->GetChildren();
|
|
||||||
size_t pos;
|
ItemList list;
|
||||||
for (pos = 0; pos < child_count; pos++)
|
list.DeleteContents( true );
|
||||||
|
if( !item.IsOk() )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
wxDataViewItem it( model->GetParent( item ) );
|
||||||
|
while( it.IsOk() )
|
||||||
{
|
{
|
||||||
if (children.Item( pos ) == id)
|
wxDataViewItem * pItem = new wxDataViewItem( it );
|
||||||
return node;
|
list.Insert( pItem );
|
||||||
|
it = model->GetParent( it );
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t node_count = node->GetNodesCount();
|
wxGtkTreeModelNode * node = treeNode;
|
||||||
for (pos = 0; pos < node_count; pos++)
|
for( ItemList::Node * n = list.GetFirst(); n; n = n->GetNext() )
|
||||||
{
|
{
|
||||||
wxGtkTreeModelNode *child = node->GetNodes().Item( pos );
|
if( node && node->GetNodes().GetCount() != 0 )
|
||||||
|
|
||||||
wxGtkTreeModelNode *node2 = wxDataViewCtrlInternal_FindParentNode( child, item );
|
|
||||||
if (node2)
|
|
||||||
{
|
{
|
||||||
// wxPrintf( "branch findnode at %d\n", i );
|
int len = node->GetNodes().GetCount();
|
||||||
return node2;
|
wxGtkTreeModelNodes nodes = node->GetNodes();
|
||||||
|
int j = 0;
|
||||||
|
for( ; j < len; j ++)
|
||||||
|
{
|
||||||
|
if( nodes[j]->GetItem() == *(n->GetData()))
|
||||||
|
{
|
||||||
|
node = nodes[j];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( j == len )
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//Examine whether the node is item's parent node
|
||||||
|
int len = node->GetChildCount();
|
||||||
|
for( int i = 0; i < len ; i ++ )
|
||||||
|
{
|
||||||
|
if( node->GetChildren().Item( i ) == item.GetID() )
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2636,7 +2687,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( GtkTreeIter *iter )
|
|||||||
if (!item.IsOk())
|
if (!item.IsOk())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return wxDataViewCtrlInternal_FindParentNode( m_root, item );
|
return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item )
|
wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item )
|
||||||
@@ -2644,7 +2695,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
|
|||||||
if (!item.IsOk())
|
if (!item.IsOk())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return wxDataViewCtrlInternal_FindParentNode( m_root, item );
|
return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user