From e07873f67e32ffeea460bfdaab03a9d0e9567847 Mon Sep 17 00:00:00 2001 From: Billy Donahue Date: Mon, 20 Sep 2021 23:39:24 +0000 Subject: SERVER-59908 simplify extendedFCVTable use --- src/mongo/util/version/releases.h.tpl | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/mongo/util/version/releases.h.tpl b/src/mongo/util/version/releases.h.tpl index 787494840cf..f006eed1ed1 100644 --- a/src/mongo/util/version/releases.h.tpl +++ b/src/mongo/util/version/releases.h.tpl @@ -223,21 +223,24 @@ inline constexpr std::array extendedFCVTable { #end for }; +constexpr decltype(auto) findExtended(FeatureCompatibilityVersion v) { + return extendedFCVTable[static_cast(v)]; +} + +constexpr StringData toString(FeatureCompatibilityVersion v) { + return findExtended(v).second; +} + /** - * A table with mappings between FeatureCompatibilityVersion::kVersion_X_Y and a pointer to the - * "X.Y"_sd generated by the extended table. Thus, this a subset of the extended table. + * Pointers to nodes of the extended table that represent numbered software versions. + * Other FCV enum members, such as those representing transitions, are excluded. */ inline constexpr std::array standardFCVTable { #for fcv, _ in filter(lambda p: p not in transition_fcvs, fcv_list): - std::pair{FeatureCompatibilityVersion::$fcv, - &extendedFCVTable[static_cast(FeatureCompatibilityVersion::$fcv)].second}, + &findExtended(FeatureCompatibilityVersion::$fcv), #end for }; -constexpr StringData toString(FeatureCompatibilityVersion v) { - return extendedFCVTable[static_cast(v)].second; -} - /** * Parses 'versionString', of the form "X.Y", to its corresponding FCV enum. For example, "5.1" * will be parsed as FeatureCompatibilityVersion::$fcv_cpp_name(Version("5.1")). @@ -245,11 +248,9 @@ constexpr StringData toString(FeatureCompatibilityVersion v) { * enum. */ inline FeatureCompatibilityVersion parseVersionForFeatureFlags(StringData versionString) { - for (const auto& [fcv, record] : standardFCVTable) { - if (*record == versionString) - return fcv; - } - + for (auto ptr : standardFCVTable) + if (ptr->second == versionString) + return ptr->first; uasserted(ErrorCodes::BadValue, fmt::format("Invalid FCV version {} for feature flag.", versionString)); } @@ -259,12 +260,10 @@ inline FeatureCompatibilityVersion parseVersionForFeatureFlags(StringData versio * version of the form 'X.Y'. Non-standard enums are transition enums, 'kInvalid' and * 'kUnsetDefaultLastLTSBehavior'. */ -inline bool isStandardFCV(FeatureCompatibilityVersion v) { - for (const auto& [fcv, record] : standardFCVTable) { - if (v == fcv) +constexpr bool isStandardFCV(FeatureCompatibilityVersion v) { + for (auto ptr : standardFCVTable) + if (ptr->first == v) return true; - } - return false; } -- cgit v1.2.1