aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/experimental-features.hh
diff options
context:
space:
mode:
authorpiegames <git@piegames.de>2024-08-18 14:43:12 +0200
committerpiegames <git@piegames.de>2024-08-18 16:56:49 +0000
commit007211e7a27a512cb343060e8b363c9f66ef67af (patch)
treef5d127d61e182049e2c1534d1ded45bc2ef265f3 /src/libutil/experimental-features.hh
parent7506d680ac540f39944c2a9f573900c5b1e4a023 (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/experimental-features.hh')
-rw-r--r--src/libutil/experimental-features.hh16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libutil/experimental-features.hh b/src/libutil/experimental-features.hh
index 121318d23..c45f05d78 100644
--- a/src/libutil/experimental-features.hh
+++ b/src/libutil/experimental-features.hh
@@ -33,6 +33,20 @@ enum struct ExperimentalFeature
ReplAutomation,
};
+enum struct ExperimentalFeatures {};
+
+inline ExperimentalFeatures operator| (ExperimentalFeatures a, ExperimentalFeatures b) {
+ return static_cast<ExperimentalFeatures>(static_cast<size_t>(a) | static_cast<size_t>(b));
+}
+
+inline ExperimentalFeatures operator| (ExperimentalFeatures a, ExperimentalFeature b) {
+ return a | static_cast<ExperimentalFeatures>(1 << static_cast<size_t>(b));
+}
+
+inline ExperimentalFeatures operator& (ExperimentalFeatures a, ExperimentalFeature b) {
+ return static_cast<ExperimentalFeatures>(static_cast<size_t>(a) & (1 << static_cast<size_t>(b)));
+}
+
/**
* Just because writing `ExperimentalFeature::CaDerivations` is way too long
*/
@@ -62,7 +76,7 @@ std::ostream & operator<<(
* Parse a set of strings to the corresponding set of experimental
* features, ignoring (but warning for) any unknown feature.
*/
-std::set<ExperimentalFeature> parseFeatures(const std::set<std::string> &);
+ExperimentalFeatures parseFeatures(const std::set<std::string> &);
/**
* An experimental feature was required for some (experimental)