Speed up finding message catalog by name in wxTranslations.

Use a helper hash map to allow efficiently finding message catalogs by name
instead of using linear search in a linked list which can be noticeably slow
when many catalogs are used.

This speeds up wxGetTranslation() when the domain is specified.

Closes #16975.
This commit is contained in:
Tomas Rapkauskas
2015-05-01 20:36:08 +03:00
committed by Vadim Zeitlin
parent d1de0f3038
commit 97286e13bd
2 changed files with 11 additions and 9 deletions

View File

@@ -1573,8 +1573,10 @@ bool wxTranslations::LoadCatalog(const wxString& domain, const wxString& lang, c
{
// add it to the head of the list so that in GetString it will
// be searched before the catalogs added earlier
cat->m_pNext = m_pMsgCat;
m_pMsgCat = cat;
m_catalogMap[domain] = cat;
return true;
}
@@ -1735,18 +1737,12 @@ wxString wxTranslations::GetHeaderValue(const wxString& header,
}
// find catalog by name in a linked list, return NULL if !found
// find catalog by name
wxMsgCatalog *wxTranslations::FindCatalog(const wxString& domain) const
{
// linear search in the linked list
wxMsgCatalog *pMsgCat;
for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext )
{
if ( pMsgCat->GetDomain() == domain )
return pMsgCat;
}
const wxMsgCatalogMap::const_iterator found = m_catalogMap.find(domain);
return NULL;
return found == m_catalogMap.end() ? NULL : found->second;
}
// ----------------------------------------------------------------------------