From d771c28613908aa8ac6aa72ceeca9048fbbcb776 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 10 Jan 2017 10:29:06 -0500 Subject: [PATCH] build-remote: Use std::set for feature sets --- src/build-remote/build-remote.cc | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index 82e5bb225..cf1062636 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,8 +24,8 @@ static void handle_alarm(int sig) { } class machine { - const std::vector supportedFeatures; - const std::vector mandatoryFeatures; + const std::set supportedFeatures; + const std::set mandatoryFeatures; public: const string hostName; @@ -35,22 +35,18 @@ public: const unsigned long long speedFactor; bool enabled; - bool allSupported(const std::vector & features) const { + bool allSupported(const std::set & features) const { return std::all_of(features.begin(), features.end(), [&](const string & feature) { - return std::find(supportedFeatures.begin(), - supportedFeatures.end(), - feature) != supportedFeatures.end() || - std::find(mandatoryFeatures.begin(), - mandatoryFeatures.end(), - feature) != mandatoryFeatures.end(); + return supportedFeatures.count(feature) || + mandatoryFeatures.count(feature); }); } - bool mandatoryMet(const std::vector & features) const { + bool mandatoryMet(const std::set & features) const { return std::all_of(mandatoryFeatures.begin(), mandatoryFeatures.end(), [&](const string & feature) { - return std::find(features.begin(), features.end(), feature) != features.end(); + return features.count(feature); }); } @@ -96,11 +92,11 @@ static std::vector read_conf() { stoull(tokens[3]), sz >= 5 ? stoull(tokens[4]) : 1LL, sz >= 6 ? - tokenizeString>(tokens[5], ",") : - std::vector{}, + tokenizeString>(tokens[5], ",") : + std::set{}, sz >= 7 ? - tokenizeString>(tokens[6], ",") : - std::vector{}); + tokenizeString>(tokens[6], ",") : + std::set{}); } } confFile.close(); @@ -160,8 +156,8 @@ int main (int argc, char * * argv) auto neededSystem = tokens[1]; drvPath = tokens[2]; auto requiredFeatures = sz == 3 ? - std::vector{} : - tokenizeString>(tokens[3], ","); + std::set{} : + tokenizeString>(tokens[3], ","); auto canBuildLocally = amWilling && (neededSystem == localSystem); /* Error ignored here, will be caught later */