comparison src/gui/translate/anilist.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 9b2b41f83a5e
children 657fda1b9cac
comparison
equal deleted inserted replaced
186:6ef31dbb90ca 187:9613d72b097e
1 #include "gui/translate/anilist.h" 1 #include "gui/translate/anilist.h"
2 #include <unordered_map>
2 3
3 namespace Translate { 4 namespace Translate {
4 namespace AniList { 5 namespace AniList {
5 6
6 Anime::SeriesStatus ToSeriesStatus(std::string status) { 7 Anime::SeriesStatus ToSeriesStatus(std::string status) {
7 const std::unordered_map<std::string, Anime::SeriesStatus> map = { 8 static const std::unordered_map<std::string, Anime::SeriesStatus> map = {
8 {"FINISHED", Anime::SeriesStatus::FINISHED }, 9 {"FINISHED", Anime::SeriesStatus::FINISHED },
9 {"RELEASING", Anime::SeriesStatus::RELEASING }, 10 {"RELEASING", Anime::SeriesStatus::RELEASING },
10 {"NOT_YET_RELEASED", Anime::SeriesStatus::NOT_YET_RELEASED}, 11 {"NOT_YET_RELEASED", Anime::SeriesStatus::NOT_YET_RELEASED},
11 {"CANCELLED", Anime::SeriesStatus::CANCELLED }, 12 {"CANCELLED", Anime::SeriesStatus::CANCELLED },
12 {"HIATUS", Anime::SeriesStatus::HIATUS } 13 {"HIATUS", Anime::SeriesStatus::HIATUS }
16 return Anime::SeriesStatus::UNKNOWN; 17 return Anime::SeriesStatus::UNKNOWN;
17 return map.at(status); 18 return map.at(status);
18 } 19 }
19 20
20 Anime::SeriesSeason ToSeriesSeason(std::string season) { 21 Anime::SeriesSeason ToSeriesSeason(std::string season) {
21 const std::unordered_map<std::string, Anime::SeriesSeason> map = { 22 static const std::unordered_map<std::string, Anime::SeriesSeason> map = {
22 {"WINTER", Anime::SeriesSeason::WINTER}, 23 {"WINTER", Anime::SeriesSeason::WINTER},
23 {"SPRING", Anime::SeriesSeason::SPRING}, 24 {"SPRING", Anime::SeriesSeason::SPRING},
24 {"SUMMER", Anime::SeriesSeason::SUMMER}, 25 {"SUMMER", Anime::SeriesSeason::SUMMER},
25 {"FALL", Anime::SeriesSeason::FALL } 26 {"FALL", Anime::SeriesSeason::FALL }
26 }; 27 };
29 return Anime::SeriesSeason::UNKNOWN; 30 return Anime::SeriesSeason::UNKNOWN;
30 return map.at(season); 31 return map.at(season);
31 } 32 }
32 33
33 Anime::SeriesFormat ToSeriesFormat(std::string format) { 34 Anime::SeriesFormat ToSeriesFormat(std::string format) {
34 const std::unordered_map<std::string, enum Anime::SeriesFormat> map = { 35 static const std::unordered_map<std::string, enum Anime::SeriesFormat> map = {
35 {"TV", Anime::SeriesFormat::TV }, 36 {"TV", Anime::SeriesFormat::TV },
36 {"TV_SHORT", Anime::SeriesFormat::TV_SHORT}, 37 {"TV_SHORT", Anime::SeriesFormat::TV_SHORT},
37 {"MOVIE", Anime::SeriesFormat::MOVIE }, 38 {"MOVIE", Anime::SeriesFormat::MOVIE },
38 {"SPECIAL", Anime::SeriesFormat::SPECIAL }, 39 {"SPECIAL", Anime::SeriesFormat::SPECIAL },
39 {"OVA", Anime::SeriesFormat::OVA }, 40 {"OVA", Anime::SeriesFormat::OVA },