diff options
author | piegames <git@piegames.de> | 2024-08-18 14:43:12 +0200 |
---|---|---|
committer | piegames <git@piegames.de> | 2024-08-18 16:56:49 +0000 |
commit | 007211e7a27a512cb343060e8b363c9f66ef67af (patch) | |
tree | f5d127d61e182049e2c1534d1ded45bc2ef265f3 /src/libutil/deprecated-features.hh | |
parent | 7506d680ac540f39944c2a9f573900c5b1e4a023 (diff) |
libutil: Optimize feature checks
Instead of doing a linear search on an std::set, we use a bitset enum.
Change-Id: Ide537f6cffdd16d06e59aaeb2e4ac0acb6493421
Diffstat (limited to 'src/libutil/deprecated-features.hh')
-rw-r--r-- | src/libutil/deprecated-features.hh | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libutil/deprecated-features.hh b/src/libutil/deprecated-features.hh index c00a5d7bd..3776e6c29 100644 --- a/src/libutil/deprecated-features.hh +++ b/src/libutil/deprecated-features.hh @@ -18,9 +18,23 @@ namespace nix { */ enum struct DeprecatedFeature { - UrlLiterals + UrlLiterals, }; +enum struct DeprecatedFeatures {}; + +inline DeprecatedFeatures operator| (DeprecatedFeatures a, DeprecatedFeatures b) { + return static_cast<DeprecatedFeatures>(static_cast<size_t>(a) | static_cast<size_t>(b)); +} + +inline DeprecatedFeatures operator| (DeprecatedFeatures a, DeprecatedFeature b) { + return a | static_cast<DeprecatedFeatures>(1 << static_cast<size_t>(b)); +} + +inline DeprecatedFeatures operator& (DeprecatedFeatures a, DeprecatedFeature b) { + return static_cast<DeprecatedFeatures>(static_cast<size_t>(a) & (1 << static_cast<size_t>(b))); +} + /** * Just because writing `DeprecatedFeature::UrlLiterals` is way too long */ @@ -50,7 +64,7 @@ std::ostream & operator<<( * Parse a set of strings to the corresponding set of deprecated * features, ignoring (but warning for) any unknown feature. */ -std::set<DeprecatedFeature> parseDeprecatedFeatures(const std::set<std::string> &); +DeprecatedFeatures parseDeprecatedFeatures(const std::set<std::string> &); /** * A deprecated feature used for some |