Use wxArrayInt methods instead of duplicating them.
Just use wxArrayInt::Index() instead of doing a linear search in the array manually. Also use RemoveAt() + Insert() instead of manually iterating over the items. See #16110. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76454 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1448,15 +1448,10 @@ public:
|
||||
if ( m_colAt.IsEmpty() )
|
||||
return idx;
|
||||
|
||||
for ( int i = 0; i < m_numCols; i++ )
|
||||
{
|
||||
if ( m_colAt[i] == idx )
|
||||
return i;
|
||||
}
|
||||
int pos = m_colAt.Index(idx);
|
||||
wxASSERT_MSG( pos != wxNOT_FOUND, "invalid column index" );
|
||||
|
||||
wxFAIL_MSG( "invalid column index" );
|
||||
|
||||
return wxNOT_FOUND;
|
||||
return pos;
|
||||
}
|
||||
|
||||
// reset the columns positions to the default order
|
||||
|
@@ -218,15 +218,10 @@ unsigned int wxHeaderCtrlBase::GetColumnPos(unsigned int idx) const
|
||||
wxCHECK_MSG( idx < count, wxNO_COLUMN, "invalid index" );
|
||||
|
||||
const wxArrayInt order = GetColumnsOrder();
|
||||
for ( unsigned n = 0; n < count; n++ )
|
||||
{
|
||||
if ( (unsigned)order[n] == idx )
|
||||
return n;
|
||||
}
|
||||
int pos = order.Index(idx);
|
||||
wxCHECK_MSG( pos != wxNOT_FOUND, wxNO_COLUMN, "column unexpectedly not displayed at all" );
|
||||
|
||||
wxFAIL_MSG( "column unexpectedly not displayed at all" );
|
||||
|
||||
return wxNO_COLUMN;
|
||||
return (unsigned int)pos;
|
||||
}
|
||||
|
||||
/* static */
|
||||
@@ -234,31 +229,14 @@ void wxHeaderCtrlBase::MoveColumnInOrderArray(wxArrayInt& order,
|
||||
unsigned int idx,
|
||||
unsigned int pos)
|
||||
{
|
||||
const unsigned count = order.size();
|
||||
int posOld = order.Index(idx);
|
||||
wxASSERT_MSG( posOld != wxNOT_FOUND, "invalid index" );
|
||||
|
||||
wxArrayInt orderNew;
|
||||
orderNew.reserve(count);
|
||||
for ( unsigned n = 0; ; n++ )
|
||||
if ( pos != (unsigned int)posOld )
|
||||
{
|
||||
// NB: order of checks is important for this to work when the new
|
||||
// column position is the same as the old one
|
||||
|
||||
// insert the column at its new position
|
||||
if ( orderNew.size() == pos )
|
||||
orderNew.push_back(idx);
|
||||
|
||||
if ( n == count )
|
||||
break;
|
||||
|
||||
// delete the column from its old position
|
||||
const unsigned idxOld = order[n];
|
||||
if ( idxOld == idx )
|
||||
continue;
|
||||
|
||||
orderNew.push_back(idxOld);
|
||||
order.RemoveAt(posOld);
|
||||
order.Insert(idx, pos);
|
||||
}
|
||||
|
||||
order.swap(orderNew);
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user