Speed up wxDataViewCtrl::SetSelections() on macOS
Don't make many single-item selection adjustments in SetSelections() in wxOSX and instead implement it with a single native call to selectRowIndexes:byExtendingSelection: This has a dramatic, orders of magnitude effect on this call's performance when selecting many items: selecting 10 thousand items goes from minutes of runtime and gigabytes of RAM to unobservable impact in both.
This commit is contained in:
@@ -514,6 +514,7 @@ public:
|
||||
virtual int GetSelections(wxDataViewItemArray& sel) const;
|
||||
virtual bool IsSelected(const wxDataViewItem& item) const;
|
||||
virtual void Select(const wxDataViewItem& item);
|
||||
virtual void Select(const wxDataViewItemArray& items);
|
||||
virtual void SelectAll();
|
||||
virtual void Unselect(const wxDataViewItem& item);
|
||||
virtual void UnselectAll();
|
||||
|
@@ -90,6 +90,7 @@ public:
|
||||
virtual int GetSelections(wxDataViewItemArray& sel) const = 0; // returns all selected items in the native control
|
||||
virtual bool IsSelected (wxDataViewItem const& item) const = 0; // checks if the passed item is selected in the native control
|
||||
virtual void Select (wxDataViewItem const& item) = 0; // selects the passed item in the native control
|
||||
virtual void Select (wxDataViewItemArray const& items) = 0; // selects the passed items in the native control
|
||||
virtual void SelectAll() = 0; // selects all items in the native control
|
||||
virtual void Unselect (wxDataViewItem const& item) = 0; // unselects the passed item in the native control
|
||||
virtual void UnselectAll() = 0; // unselects all items in the native control
|
||||
|
@@ -2508,6 +2508,20 @@ void wxCocoaDataViewControl::Select(const wxDataViewItem& item)
|
||||
byExtendingSelection:GetDataViewCtrl()->HasFlag(wxDV_MULTIPLE) ? YES : NO];
|
||||
}
|
||||
|
||||
void wxCocoaDataViewControl::Select(const wxDataViewItemArray& items)
|
||||
{
|
||||
NSMutableIndexSet *selection = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
for ( const auto& i: items )
|
||||
{
|
||||
if ( i.IsOk() )
|
||||
[selection addIndex:[m_OutlineView rowForItem:[m_DataSource getDataViewItemFromBuffer:i]]];
|
||||
}
|
||||
|
||||
[m_OutlineView selectRowIndexes:selection byExtendingSelection:NO];
|
||||
[selection release];
|
||||
}
|
||||
|
||||
void wxCocoaDataViewControl::SelectAll()
|
||||
{
|
||||
[m_OutlineView selectAll:m_OutlineView];
|
||||
|
@@ -648,8 +648,7 @@ void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
|
||||
}
|
||||
|
||||
// finally select the items:
|
||||
for (i=0; i<noOfSelections; ++i)
|
||||
dataViewWidgetPtr->Select(sel[i]);
|
||||
dataViewWidgetPtr->Select(sel);
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
|
||||
|
Reference in New Issue
Block a user