From: Robert Roebling Date: Thu, 15 Nov 2007 15:03:48 +0000 (+0000) Subject: optimise startup of wxDataViewIndexListModel X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/517166e678f9e70f94ea6970356c12550bedadc5 optimise startup of wxDataViewIndexListModel git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49970 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 022ff17bd5..fbfc5dce44 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -255,7 +255,7 @@ public: virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, unsigned int column, bool ascending ); - virtual bool HasDefaultCompare() const { return true; } + virtual bool HasDefaultCompare() const; // implement base methods @@ -271,6 +271,7 @@ public: private: wxDataViewItemArray m_hash; unsigned int m_lastIndex; + bool m_ordered; }; diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index b5f49859fc..af4de712b2 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -299,6 +299,8 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) { + m_ordered = true; + // build initial index unsigned int i; for (i = 1; i < initial_size+1; i++) @@ -316,6 +318,8 @@ void wxDataViewIndexListModel::RowPrepended() m_hash.Insert( (void*) id, 0 ); wxDataViewItem item( (void*) id ); ItemAdded( wxDataViewItem(0), item ); + + m_ordered = false; } void wxDataViewIndexListModel::RowInserted( unsigned int before ) @@ -324,6 +328,8 @@ void wxDataViewIndexListModel::RowInserted( unsigned int before ) m_hash.Insert( (void*) id, before ); wxDataViewItem item( (void*) id ); ItemAdded( wxDataViewItem(0), item ); + + m_ordered = false; } void wxDataViewIndexListModel::RowAppended() @@ -353,6 +359,12 @@ void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int c unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const { + if (m_ordered) + { + unsigned int pos = (unsigned int) item.GetID(); + return pos-1; + } + // assert for not found return (unsigned int) m_hash.Index( item.GetID() ); } @@ -363,11 +375,27 @@ wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const return wxDataViewItem( m_hash[row] ); } +bool wxDataViewIndexListModel::HasDefaultCompare() const +{ + return !m_ordered; +} + int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1, const wxDataViewItem& item2, unsigned int WXUNUSED(column), bool ascending) { + if (m_ordered) + { + unsigned int pos1 = (unsigned int) item1.GetID(); + unsigned int pos2 = (unsigned int) item2.GetID(); + + if (ascending) + return pos1 - pos2; + else + return pos2 - pos1; + } + if (ascending) return GetRow(item1) - GetRow(item2);