From fdbfe3753b8451c943cfa4a6bc9a33bf93dc0146 Mon Sep 17 00:00:00 2001 From: lostystyg Date: Thu, 11 Aug 2022 15:55:31 +0400 Subject: [PATCH] Fixed static initialization order problem --- src/pocketdb/helpers/ShortFormHelper.cpp | 31 ++++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/pocketdb/helpers/ShortFormHelper.cpp b/src/pocketdb/helpers/ShortFormHelper.cpp index f6dbeba75..ad8af9678 100644 --- a/src/pocketdb/helpers/ShortFormHelper.cpp +++ b/src/pocketdb/helpers/ShortFormHelper.cpp @@ -9,22 +9,26 @@ #include -static const std::map typesMap = { - { PocketDb::ShortTxType::PocketnetTeam, "pocketnetteam" }, - { PocketDb::ShortTxType::Money, "money" }, - { PocketDb::ShortTxType::Referal, "referal" }, - { PocketDb::ShortTxType::Answer, "answer" }, - { PocketDb::ShortTxType::Comment, "comment" }, - { PocketDb::ShortTxType::Subscriber, "subscriber" }, - { PocketDb::ShortTxType::CommentScore, "commentscore" }, - { PocketDb::ShortTxType::ContentScore, "contentscore" }, - { PocketDb::ShortTxType::PrivateContent, "privatecontent" }, - { PocketDb::ShortTxType::Boost, "boost" }, - { PocketDb::ShortTxType::Repost, "repost" }, -}; +static const std::map& GetTypesMap() { + static const std::map typesMap = { + { PocketDb::ShortTxType::PocketnetTeam, "pocketnetteam" }, + { PocketDb::ShortTxType::Money, "money" }, + { PocketDb::ShortTxType::Referal, "referal" }, + { PocketDb::ShortTxType::Answer, "answer" }, + { PocketDb::ShortTxType::Comment, "comment" }, + { PocketDb::ShortTxType::Subscriber, "subscriber" }, + { PocketDb::ShortTxType::CommentScore, "commentscore" }, + { PocketDb::ShortTxType::ContentScore, "contentscore" }, + { PocketDb::ShortTxType::PrivateContent, "privatecontent" }, + { PocketDb::ShortTxType::Boost, "boost" }, + { PocketDb::ShortTxType::Repost, "repost" }, + }; + return typesMap; +} std::string PocketHelpers::ShortTxTypeConvertor::toString(PocketDb::ShortTxType type) { + static const auto& typesMap = GetTypesMap(); auto str = typesMap.find(type); if (str != typesMap.end()) { return str->second; @@ -47,6 +51,7 @@ bool PocketHelpers::ShortTxFilterValidator::Notifications::IsFilterAllowed(Pocke PocketDb::ShortTxType PocketHelpers::ShortTxTypeConvertor::strToType(const std::string& typeStr) { + static const auto& typesMap = GetTypesMap(); auto type = std::find_if(typesMap.begin(), typesMap.end(), [&](const auto& elem) { return elem.second == typeStr; }); if (type != typesMap.end()) { return type->first;