diff --git a/src/base/crypto/Algorithm.cpp b/src/base/crypto/Algorithm.cpp index a5b8b5626..18adcf4e0 100644 --- a/src/base/crypto/Algorithm.cpp +++ b/src/base/crypto/Algorithm.cpp @@ -106,7 +106,12 @@ const char *Algorithm::kKAWPOW_RVN = "kawpow"; #define ALGO_ALIAS_AUTO(ALGO) { Algorithm::k##ALGO, Algorithm::ALGO } -static const std::map kAlgorithmNames = { +#ifdef _MSC_VER +# define strcasecmp _stricmp +#endif + + +static const std::map kAlgorithmNames = { ALGO_NAME(CN_0), ALGO_NAME(CN_1), ALGO_NAME(CN_2), @@ -166,7 +171,7 @@ static const std::map kAlgorithmNames = { struct aliasCompare { - inline bool operator()(const char *a, const char *b) const { return std::strcmp(a, b) < 0; } + inline bool operator()(const char *a, const char *b) const { return strcasecmp(a, b) < 0; } }; @@ -286,6 +291,12 @@ xmrig::Algorithm::Algorithm(const rapidjson::Value &value) : } +xmrig::Algorithm::Algorithm(uint32_t id) : + m_id(kAlgorithmNames.count(id) ? static_cast(id) : INVALID) +{ +} + + const char *xmrig::Algorithm::name() const { if (!isValid()) { @@ -319,7 +330,7 @@ xmrig::Algorithm::Id xmrig::Algorithm::parse(const char *name) return INVALID; } - const auto it = kAlgorithmAliases.find(String(name).toLower()); + const auto it = kAlgorithmAliases.find(name); return it != kAlgorithmAliases.end() ? it->second : INVALID; } @@ -331,27 +342,26 @@ size_t xmrig::Algorithm::count() } -std::vector xmrig::Algorithm::all() -{ - Algorithms out; - out.reserve(count()); - - for (const auto &kv : kAlgorithmNames) { - out.emplace_back(kv.first); - } - - return out; -} - - std::vector xmrig::Algorithm::all(const std::function &filter) { + static const std::vector order = { + CN_0, CN_1, CN_2, CN_R, CN_FAST, CN_HALF, CN_XAO, CN_RTO, CN_RWZ, CN_ZLS, CN_DOUBLE, CN_CCX, + CN_LITE_0, CN_LITE_1, + CN_HEAVY_0, CN_HEAVY_TUBE, CN_HEAVY_XHV, + CN_PICO_0, CN_PICO_TLO, + CN_UPX2, + RX_0, RX_WOW, RX_ARQ, RX_SFX, RX_KEVA, + AR2_CHUKWA, AR2_CHUKWA_V2, AR2_WRKZ, + ASTROBWT_DERO, + KAWPOW_RVN + }; + Algorithms out; out.reserve(count()); - for (const auto &kv : kAlgorithmNames) { - if (filter(kv.first)) { - out.emplace_back(kv.first); + for (const Id algo : order) { + if (kAlgorithmNames.count(algo) && (!filter || filter(algo))) { + out.emplace_back(algo); } } diff --git a/src/base/crypto/Algorithm.h b/src/base/crypto/Algorithm.h index 8b03e0701..4fc6de7a4 100644 --- a/src/base/crypto/Algorithm.h +++ b/src/base/crypto/Algorithm.h @@ -159,6 +159,7 @@ public: inline Algorithm(const char *algo) : m_id(parse(algo)) {} inline Algorithm(Id id) : m_id(id) {} Algorithm(const rapidjson::Value &value); + Algorithm(uint32_t id); static inline constexpr bool isCN(Id id) { return (id & 0xff000000) == CN_ANY; } static inline constexpr Id base(Id id) { return isCN(id) ? static_cast(CN_0 | (id & 0xff00)) : INVALID; } @@ -196,8 +197,7 @@ public: static Id parse(const char *name); static size_t count(); - static std::vector all(); - static std::vector all(const std::function &filter); + static std::vector all(const std::function &filter = nullptr); private: Id m_id = INVALID;