Skip to content

Commit

Permalink
Revert CatalogItem::GetTranslation() optimization
Browse files Browse the repository at this point in the history
Partially reverts 1ed2ac3.

Don't specialize GetTranslation() (i.e. n=0) to return a reference. It
doesn't have measurable effect after the other optimizations and it
causes crashes in code that implicitly assumes that GetTranslation() is
safe to call e.g. on non-translation files too (see e.g. 6b893be).

It's just not worth the risk.
  • Loading branch information
vslavik committed May 6, 2024
1 parent 6b893be commit 305e676
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ void CatalogItem::SetFuzzy(bool fuzzy)
wxString CatalogItem::GetTranslation(unsigned idx) const
{
if (idx >= GetNumberOfTranslations())
return wxEmptyString;
return wxString();
else
return m_translations[idx];
}
Expand Down
3 changes: 1 addition & 2 deletions src/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ class CatalogItem
unsigned GetPluralFormsCount() const;

/// Returns the nth-translation.
wxString GetTranslation(unsigned n) const;
const wxString& GetTranslation() const { return m_translations[0]; }
wxString GetTranslation(unsigned n = 0) const;

/// Returns all translations.
const wxArrayString& GetTranslations() const { return m_translations; }
Expand Down

0 comments on commit 305e676

Please sign in to comment.