Mercurial > minori
comparison src/services/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 | 62e336597bb7 |
| children | 7cf53145de11 |
comparison
equal
deleted
inserted
replaced
| 186:6ef31dbb90ca | 187:9613d72b097e |
|---|---|
| 5 #include "core/http.h" | 5 #include "core/http.h" |
| 6 #include "core/json.h" | 6 #include "core/json.h" |
| 7 #include "core/session.h" | 7 #include "core/session.h" |
| 8 #include "core/strings.h" | 8 #include "core/strings.h" |
| 9 #include "gui/translate/anilist.h" | 9 #include "gui/translate/anilist.h" |
| 10 | |
| 11 #include <QDate> | |
| 10 #include <QByteArray> | 12 #include <QByteArray> |
| 11 #include <QDesktopServices> | 13 #include <QDesktopServices> |
| 12 #include <QInputDialog> | 14 #include <QInputDialog> |
| 13 #include <QLineEdit> | 15 #include <QLineEdit> |
| 14 #include <QMessageBox> | 16 #include <QMessageBox> |
| 15 #include <QUrl> | 17 #include <QUrl> |
| 18 | |
| 16 #include <chrono> | 19 #include <chrono> |
| 17 #include <exception> | 20 #include <exception> |
| 18 | 21 |
| 19 #include <iostream> | 22 #include <iostream> |
| 20 | 23 |
| 70 | 73 |
| 71 return ret; | 74 return ret; |
| 72 } | 75 } |
| 73 | 76 |
| 74 void ParseListStatus(std::string status, Anime::Anime& anime) { | 77 void ParseListStatus(std::string status, Anime::Anime& anime) { |
| 75 std::unordered_map<std::string, Anime::ListStatus> map = { | 78 static const std::unordered_map<std::string, Anime::ListStatus> map = { |
| 76 {"CURRENT", Anime::ListStatus::CURRENT }, | 79 {"CURRENT", Anime::ListStatus::CURRENT }, |
| 77 {"PLANNING", Anime::ListStatus::PLANNING }, | 80 {"PLANNING", Anime::ListStatus::PLANNING }, |
| 78 {"COMPLETED", Anime::ListStatus::COMPLETED}, | 81 {"COMPLETED", Anime::ListStatus::COMPLETED}, |
| 79 {"DROPPED", Anime::ListStatus::DROPPED }, | 82 {"DROPPED", Anime::ListStatus::DROPPED }, |
| 80 {"PAUSED", Anime::ListStatus::PAUSED } | 83 {"PAUSED", Anime::ListStatus::PAUSED } |
| 89 if (map.find(status) == map.end()) { | 92 if (map.find(status) == map.end()) { |
| 90 anime.SetUserStatus(Anime::ListStatus::NOT_IN_LIST); | 93 anime.SetUserStatus(Anime::ListStatus::NOT_IN_LIST); |
| 91 return; | 94 return; |
| 92 } | 95 } |
| 93 | 96 |
| 94 anime.SetUserStatus(map[status]); | 97 anime.SetUserStatus(map.at(status)); |
| 95 } | 98 } |
| 96 | 99 |
| 97 std::string ListStatusToString(const Anime::Anime& anime) { | 100 std::string ListStatusToString(const Anime::Anime& anime) { |
| 98 if (anime.GetUserIsRewatching()) | 101 if (anime.GetUserIsRewatching()) |
| 99 return "REWATCHING"; | 102 return "REWATCHING"; |
