Mercurial > minori
diff src/gui/translate/anime.cc @ 187:9613d72b097e
*: multiple performance improvements
like marking `static const` when it makes sense...
date: change old stupid heap-based method to a structure which should
make copying the thing actually make a copy.
also many performance-based changes, like removing the std::tie
dependency and forward-declaring nlohmann json
*: replace every instance of QString::fromUtf8 to Strings::ToQString.
the main difference is that our function will always convert exactly
what is in the string, while some other times it would only convert
up to the nearest NUL byte
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 13:43:54 -0500 |
parents | 62e336597bb7 |
children | 71832ffe425a |
line wrap: on
line diff
--- a/src/gui/translate/anime.cc Wed Dec 06 11:47:59 2023 -0500 +++ b/src/gui/translate/anime.cc Wed Dec 06 13:43:54 2023 -0500 @@ -83,7 +83,7 @@ } Anime::ListStatus ToListStatus(const std::string& str) { - const std::unordered_map<std::string, Anime::ListStatus> map = { + static const std::unordered_map<std::string, Anime::ListStatus> map = { {"Currently watching", Anime::ListStatus::CURRENT}, {"Plan to watch", Anime::ListStatus::PLANNING}, {"Completed", Anime::ListStatus::COMPLETED}, @@ -97,7 +97,7 @@ } Anime::SeriesStatus ToSeriesStatus(const std::string& str) { - const std::unordered_map<std::string, Anime::SeriesStatus> map = { + static const std::unordered_map<std::string, Anime::SeriesStatus> map = { {"Currently airing", Anime::SeriesStatus::RELEASING}, {"Finished airing", Anime::SeriesStatus::FINISHED}, {"Not yet aired", Anime::SeriesStatus::NOT_YET_RELEASED}, @@ -111,7 +111,7 @@ } Anime::SeriesSeason ToSeriesSeason(const std::string& str) { - const std::unordered_map<std::string, Anime::SeriesSeason> map = { + static const std::unordered_map<std::string, Anime::SeriesSeason> map = { {"Winter", Anime::SeriesSeason::WINTER}, {"Summer", Anime::SeriesSeason::SUMMER}, {"Fall", Anime::SeriesSeason::FALL}, @@ -124,7 +124,7 @@ } Anime::SeriesFormat ToSeriesFormat(const std::string& str) { - const std::unordered_map<std::string, Anime::SeriesFormat> map = { + static const std::unordered_map<std::string, Anime::SeriesFormat> map = { {"TV", Anime::SeriesFormat::TV}, {"TV short", Anime::SeriesFormat::TV_SHORT}, {"OVA", Anime::SeriesFormat::OVA}, @@ -140,7 +140,7 @@ } Anime::Services ToService(const std::string& str) { - const std::unordered_map<std::string, Anime::Services> map = { + static const std::unordered_map<std::string, Anime::Services> map = { {"AniList", Anime::Services::ANILIST} }; @@ -150,7 +150,7 @@ } Anime::TitleLanguage ToLanguage(const std::string& str) { - const std::unordered_map<std::string, Anime::TitleLanguage> map = { + static const std::unordered_map<std::string, Anime::TitleLanguage> map = { {"Romaji", Anime::TitleLanguage::ROMAJI}, {"Native", Anime::TitleLanguage::NATIVE}, {"English", Anime::TitleLanguage::ENGLISH} @@ -162,7 +162,7 @@ } Anime::ScoreFormat ToScoreFormat(const std::string& str) { - const std::unordered_map<std::string, Anime::ScoreFormat> map = { + static const std::unordered_map<std::string, Anime::ScoreFormat> map = { {"POINT_3", Anime::ScoreFormat::POINT_3}, {"POINT_5", Anime::ScoreFormat::POINT_5}, {"POINT_10", Anime::ScoreFormat::POINT_10}, @@ -175,7 +175,7 @@ return map.at(str); } -/* Localized versions of ToString() functions */ +/* Localized versions of ToString() functions. Meant for display to the user. */ std::string ToLocalString(const Anime::ListStatus status) { switch (status) { @@ -243,4 +243,15 @@ } } +std::string ToLocalString(const Anime::ScoreFormat format) { + switch (format) { + case Anime::ScoreFormat::POINT_3: return Strings::ToUtf8String(QCoreApplication::tr("3-point")); + case Anime::ScoreFormat::POINT_5: return Strings::ToUtf8String(QCoreApplication::tr("5-point")); + case Anime::ScoreFormat::POINT_10: return Strings::ToUtf8String(QCoreApplication::tr("10-point")); + case Anime::ScoreFormat::POINT_10_DECIMAL: return Strings::ToUtf8String(QCoreApplication::tr("10-point (Decimal)")); + default: + case Anime::ScoreFormat::POINT_100: return Strings::ToUtf8String(QCoreApplication::tr("100-point")); + } +} + } // namespace Translate