Optimize component chooser startup time more

- Stop wx from sorting the items. We've already sorted them, and
  profiling shows our sort is faster than theirs.

- Go back to using strings as cache keys, because using pointers means
  the cache doesn't survive from one invocation to the next. Switch to
  wxHashMap because it can use wxString keys in an unordered (faster)
  map.
This commit is contained in:
Chris Pavlina 2017-03-08 14:41:34 -05:00
parent 28848373ce
commit 7ee0adabd7
2 changed files with 8 additions and 33 deletions

View File

@ -307,20 +307,6 @@ void CMP_TREE_MODEL_ADAPTER::GetValue(
} }
int CMP_TREE_MODEL_ADAPTER::Compare(
wxDataViewItem const& aFirst, wxDataViewItem const& aSecond,
unsigned int aCol, bool aAscending ) const
{
auto node1 = ToNode( aFirst );
auto node2 = ToNode( aSecond );
if( aAscending )
return -CMP_TREE_NODE::Compare(*node1, *node2);
else
return CMP_TREE_NODE::Compare(*node1, *node2);
}
int CMP_TREE_MODEL_ADAPTER::ColWidth( CMP_TREE_NODE& aTree, int aCol, wxString const& aHeading ) int CMP_TREE_MODEL_ADAPTER::ColWidth( CMP_TREE_NODE& aTree, int aCol, wxString const& aHeading )
{ {
const int indent = aCol ? 0 : kDataViewIndent; const int indent = aCol ? 0 : kDataViewIndent;
@ -342,7 +328,7 @@ int CMP_TREE_MODEL_ADAPTER::ColWidth( CMP_TREE_NODE& aTree, int aCol, wxString c
int CMP_TREE_MODEL_ADAPTER::WidthFor( CMP_TREE_NODE& aNode, int aCol ) int CMP_TREE_MODEL_ADAPTER::WidthFor( CMP_TREE_NODE& aNode, int aCol )
{ {
auto result = m_width_cache.find( &aNode ); auto result = m_width_cache.find( aNode.Name );
if( result != m_width_cache.end() ) if( result != m_width_cache.end() )
{ {
@ -353,9 +339,10 @@ int CMP_TREE_MODEL_ADAPTER::WidthFor( CMP_TREE_NODE& aNode, int aCol )
int wname = m_widget->GetTextExtent( aNode.Name ).x + kDataViewIndent; int wname = m_widget->GetTextExtent( aNode.Name ).x + kDataViewIndent;
int wdesc = m_widget->GetTextExtent( aNode.Desc ).x; int wdesc = m_widget->GetTextExtent( aNode.Desc ).x;
m_width_cache[&aNode].push_back( wname ); auto& val = m_width_cache[aNode.Name];
m_width_cache[&aNode].push_back( wdesc ); val.push_back( wname );
return m_width_cache[&aNode][aCol]; val.push_back( wdesc );
return val[aCol];
} }
} }

View File

@ -24,6 +24,7 @@
#include <cmp_tree_model.h> #include <cmp_tree_model.h>
#include <wx/hashmap.h>
#include <wx/dataview.h> #include <wx/dataview.h>
#include <vector> #include <vector>
#include <unordered_map> #include <unordered_map>
@ -279,20 +280,6 @@ protected:
wxDataViewItem const& aItem, wxDataViewItem const& aItem,
unsigned int aCol ) const override; unsigned int aCol ) const override;
/**
* Compare two data items, for sorting.
*/
virtual int Compare(
wxDataViewItem const& aFirst,
wxDataViewItem const& aSecond,
unsigned int aCol,
bool aAscending ) const override;
/**
* Whether list is sorted even if the user hasn't selected a sort column
*/
virtual bool HasDefaultCompare() const override { return true; }
/** /**
* Set the value of an item. Does nothing - this model doesn't support * Set the value of an item. Does nothing - this model doesn't support
* editing. * editing.
@ -315,7 +302,8 @@ private:
wxDataViewColumn* m_col_desc; wxDataViewColumn* m_col_desc;
wxDataViewCtrl* m_widget; wxDataViewCtrl* m_widget;
typedef std::unordered_map<CMP_TREE_NODE*, std::vector<int>> WIDTH_CACHE; WX_DECLARE_STRING_HASH_MAP( std::vector<int>, WIDTH_CACHE );
//typedef std::unordered_map<std::string, std::vector<int>> WIDTH_CACHE;
static WIDTH_CACHE m_width_cache; static WIDTH_CACHE m_width_cache;