mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-12 15:46:25 +01:00
Faster opening of preferences.
The slow opening was caused by sorting lists of commands. The comparison function was slow because it created new strings, entailing malloc/free and used translation in the function. Comparison function was being called about 4,000 times.
This commit is contained in:
@@ -47,6 +47,9 @@ BEGIN_EVENT_TABLE(KeyView, wxVListBox)
|
|||||||
EVT_SCROLLWIN(KeyView::OnScroll)
|
EVT_SCROLLWIN(KeyView::OnScroll)
|
||||||
END_EVENT_TABLE();
|
END_EVENT_TABLE();
|
||||||
|
|
||||||
|
wxString KeyView::CommandTranslated="Command";
|
||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// KeyView class
|
// KeyView class
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -915,6 +918,12 @@ KeyView::RefreshLines()
|
|||||||
mLines.Add(&node);
|
mLines.Add(&node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//To see how many lines are being sorted (and how often).
|
||||||
|
//wxLogDebug("Sorting %i lines", mLines.GetCount());
|
||||||
|
|
||||||
|
// Speed up the comparison function used in sorting
|
||||||
|
// by only translating this string once.
|
||||||
|
CommandTranslated = _("Command");
|
||||||
|
|
||||||
// Sort list based on type
|
// Sort list based on type
|
||||||
switch (mViewType)
|
switch (mViewType)
|
||||||
@@ -1544,48 +1553,30 @@ KeyView::CmpKeyNodeByTree(KeyNode ***n1, KeyNode ***n2)
|
|||||||
{
|
{
|
||||||
KeyNode *t1 = (**n1);
|
KeyNode *t1 = (**n1);
|
||||||
KeyNode *t2 = (**n2);
|
KeyNode *t2 = (**n2);
|
||||||
wxString k1 = t1->label;
|
|
||||||
wxString k2 = t2->label;
|
unsigned int k1UInt= 0xffffffff;
|
||||||
|
unsigned int k2UInt= 0xffffffff;
|
||||||
|
|
||||||
// This is a "command" node if its category is "Command"
|
// This is a "command" node if its category is "Command"
|
||||||
// and it is a child of the "Command" category. This latter
|
// and it is a child of the "Command" category. This latter
|
||||||
// test ensures that the "Command" parent will be handled
|
// test ensures that the "Command" parent will be handled
|
||||||
// as a "menu" node and remain at the bottom of the list.
|
// as a "menu" node and remain at the bottom of the list.
|
||||||
if (t1->category == _("Command") && !t1->isparent)
|
if (t1->category != CommandTranslated || t1->isparent)
|
||||||
{
|
k1UInt = (unsigned int) t1->line;
|
||||||
// A "command" node, so prepend the highest hex value
|
|
||||||
k1.Printf(wxT("ffffffff%s"), t1->label.c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// A "menu" node, so prepend the line number
|
|
||||||
k1.Printf(wxT("%08x%s"), (unsigned int) t1->line, t1->label.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// See above for explanation
|
// See above for explanation
|
||||||
if (t2->category == _("Command") && !t2->isparent)
|
if (t2->category != CommandTranslated || t2->isparent)
|
||||||
{
|
k2UInt = (unsigned int) t2->line;
|
||||||
// A "command" node, so prepend the highest hex value
|
|
||||||
k2.Printf(wxT("ffffffff%s"), t2->label.c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// A "menu" node, so prepend the line number
|
|
||||||
k2.Printf(wxT("%08x%s"), (unsigned int) t2->line, t2->label.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// See wxWidgets documentation for explanation of comparison results.
|
if( k1UInt < k2UInt )
|
||||||
// These will produce an ascending order.
|
|
||||||
if (k1 < k2)
|
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
if( k1UInt > k2UInt )
|
||||||
|
return +1;
|
||||||
|
|
||||||
if (k1 > k2)
|
if( t1->label < t2->label )
|
||||||
{
|
return -1;
|
||||||
|
if( t1->label > t2->label )
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ private:
|
|||||||
void OnKeyDown(wxKeyEvent & event);
|
void OnKeyDown(wxKeyEvent & event);
|
||||||
void OnLeftDown(wxMouseEvent & event);
|
void OnLeftDown(wxMouseEvent & event);
|
||||||
|
|
||||||
|
|
||||||
|
static wxString CommandTranslated;
|
||||||
static int CmpKeyNodeByTree(KeyNode ***n1, KeyNode ***n2);
|
static int CmpKeyNodeByTree(KeyNode ***n1, KeyNode ***n2);
|
||||||
static int CmpKeyNodeByName(KeyNode ***n1, KeyNode ***n2);
|
static int CmpKeyNodeByName(KeyNode ***n1, KeyNode ***n2);
|
||||||
static int CmpKeyNodeByKey(KeyNode ***n1, KeyNode ***n2);
|
static int CmpKeyNodeByKey(KeyNode ***n1, KeyNode ***n2);
|
||||||
|
|||||||
Reference in New Issue
Block a user