Mercurial > minori
annotate 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 |
rev | line source |
---|---|
15 | 1 #include "gui/translate/anilist.h" |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
2 #include <unordered_map> |
15 | 3 |
63 | 4 namespace Translate { |
5 namespace AniList { | |
15 | 6 |
7 Anime::SeriesStatus ToSeriesStatus(std::string status) { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
8 static const std::unordered_map<std::string, Anime::SeriesStatus> map = { |
15 | 9 {"FINISHED", Anime::SeriesStatus::FINISHED }, |
10 {"RELEASING", Anime::SeriesStatus::RELEASING }, | |
11 {"NOT_YET_RELEASED", Anime::SeriesStatus::NOT_YET_RELEASED}, | |
12 {"CANCELLED", Anime::SeriesStatus::CANCELLED }, | |
13 {"HIATUS", Anime::SeriesStatus::HIATUS } | |
14 }; | |
15 | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
16 if (map.find(status) == map.end()) |
15 | 17 return Anime::SeriesStatus::UNKNOWN; |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
18 return map.at(status); |
15 | 19 } |
20 | |
21 Anime::SeriesSeason ToSeriesSeason(std::string season) { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
22 static const std::unordered_map<std::string, Anime::SeriesSeason> map = { |
15 | 23 {"WINTER", Anime::SeriesSeason::WINTER}, |
24 {"SPRING", Anime::SeriesSeason::SPRING}, | |
25 {"SUMMER", Anime::SeriesSeason::SUMMER}, | |
26 {"FALL", Anime::SeriesSeason::FALL } | |
27 }; | |
28 | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
29 if (map.find(season) == map.end()) |
15 | 30 return Anime::SeriesSeason::UNKNOWN; |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
31 return map.at(season); |
15 | 32 } |
33 | |
34 Anime::SeriesFormat ToSeriesFormat(std::string format) { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
35 static const std::unordered_map<std::string, enum Anime::SeriesFormat> map = { |
15 | 36 {"TV", Anime::SeriesFormat::TV }, |
37 {"TV_SHORT", Anime::SeriesFormat::TV_SHORT}, | |
38 {"MOVIE", Anime::SeriesFormat::MOVIE }, | |
39 {"SPECIAL", Anime::SeriesFormat::SPECIAL }, | |
40 {"OVA", Anime::SeriesFormat::OVA }, | |
41 {"ONA", Anime::SeriesFormat::ONA }, | |
42 {"MUSIC", Anime::SeriesFormat::MUSIC }, | |
43 {"MANGA", Anime::SeriesFormat::MANGA }, | |
44 {"NOVEL", Anime::SeriesFormat::NOVEL }, | |
45 {"ONE_SHOT", Anime::SeriesFormat::ONE_SHOT} | |
46 }; | |
47 | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
48 if (map.find(format) == map.end()) |
15 | 49 return Anime::SeriesFormat::UNKNOWN; |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
50 return map.at(format); |
15 | 51 } |
52 | |
63 | 53 } // namespace AniList |
54 } // namespace Translate |