optimise startup of wxDataViewIndexListModel
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49970 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -255,7 +255,7 @@ public:
|
|||||||
|
|
||||||
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||||
unsigned int column, bool ascending );
|
unsigned int column, bool ascending );
|
||||||
virtual bool HasDefaultCompare() const { return true; }
|
virtual bool HasDefaultCompare() const;
|
||||||
|
|
||||||
// implement base methods
|
// implement base methods
|
||||||
|
|
||||||
@@ -271,6 +271,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
wxDataViewItemArray m_hash;
|
wxDataViewItemArray m_hash;
|
||||||
unsigned int m_lastIndex;
|
unsigned int m_lastIndex;
|
||||||
|
bool m_ordered;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -299,6 +299,8 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem
|
|||||||
|
|
||||||
wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
|
wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
|
||||||
{
|
{
|
||||||
|
m_ordered = true;
|
||||||
|
|
||||||
// build initial index
|
// build initial index
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 1; i < initial_size+1; i++)
|
for (i = 1; i < initial_size+1; i++)
|
||||||
@@ -316,6 +318,8 @@ void wxDataViewIndexListModel::RowPrepended()
|
|||||||
m_hash.Insert( (void*) id, 0 );
|
m_hash.Insert( (void*) id, 0 );
|
||||||
wxDataViewItem item( (void*) id );
|
wxDataViewItem item( (void*) id );
|
||||||
ItemAdded( wxDataViewItem(0), item );
|
ItemAdded( wxDataViewItem(0), item );
|
||||||
|
|
||||||
|
m_ordered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewIndexListModel::RowInserted( unsigned int before )
|
void wxDataViewIndexListModel::RowInserted( unsigned int before )
|
||||||
@@ -324,6 +328,8 @@ void wxDataViewIndexListModel::RowInserted( unsigned int before )
|
|||||||
m_hash.Insert( (void*) id, before );
|
m_hash.Insert( (void*) id, before );
|
||||||
wxDataViewItem item( (void*) id );
|
wxDataViewItem item( (void*) id );
|
||||||
ItemAdded( wxDataViewItem(0), item );
|
ItemAdded( wxDataViewItem(0), item );
|
||||||
|
|
||||||
|
m_ordered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewIndexListModel::RowAppended()
|
void wxDataViewIndexListModel::RowAppended()
|
||||||
@@ -353,6 +359,12 @@ void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int c
|
|||||||
|
|
||||||
unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
|
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
|
// assert for not found
|
||||||
return (unsigned int) m_hash.Index( item.GetID() );
|
return (unsigned int) m_hash.Index( item.GetID() );
|
||||||
}
|
}
|
||||||
@@ -363,11 +375,27 @@ wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
|
|||||||
return wxDataViewItem( m_hash[row] );
|
return wxDataViewItem( m_hash[row] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxDataViewIndexListModel::HasDefaultCompare() const
|
||||||
|
{
|
||||||
|
return !m_ordered;
|
||||||
|
}
|
||||||
|
|
||||||
int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
|
int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
|
||||||
const wxDataViewItem& item2,
|
const wxDataViewItem& item2,
|
||||||
unsigned int WXUNUSED(column),
|
unsigned int WXUNUSED(column),
|
||||||
bool ascending)
|
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)
|
if (ascending)
|
||||||
return GetRow(item1) - GetRow(item2);
|
return GetRow(item1) - GetRow(item2);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user