From 689ef502f5b0655c9923ed77da2ae3504630f473 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 20 May 2020 22:27:37 +0100 Subject: refactor(3p/nix): Apply clang-tidy's readability-* fixes This applies the readability fixes listed here: https://clang.llvm.org/extra/clang-tidy/checks/list.html --- third_party/nix/src/libstore/parsed-derivations.cc | 61 ++++++++++------------ 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'third_party/nix/src/libstore/parsed-derivations.cc') diff --git a/third_party/nix/src/libstore/parsed-derivations.cc b/third_party/nix/src/libstore/parsed-derivations.cc index ec158e0ab1a0..1186203249de 100644 --- a/third_party/nix/src/libstore/parsed-derivations.cc +++ b/third_party/nix/src/libstore/parsed-derivations.cc @@ -22,20 +22,19 @@ std::optional ParsedDerivation::getStringAttr( auto i = structuredAttrs->find(name); if (i == structuredAttrs->end()) { return {}; - } else { - if (!i->is_string()) { - throw Error("attribute '%s' of derivation '%s' must be a string", name, - drvPath); - } - return i->get(); } + if (!i->is_string()) { + throw Error("attribute '%s' of derivation '%s' must be a string", name, + drvPath); + } + return i->get(); + } else { auto i = drv.env.find(name); if (i == drv.env.end()) { return {}; - } else { - return i->second; } + return i->second; } } @@ -44,20 +43,19 @@ bool ParsedDerivation::getBoolAttr(const std::string& name, bool def) const { auto i = structuredAttrs->find(name); if (i == structuredAttrs->end()) { return def; - } else { - if (!i->is_boolean()) { - throw Error("attribute '%s' of derivation '%s' must be a Boolean", name, - drvPath); - } - return i->get(); } + if (!i->is_boolean()) { + throw Error("attribute '%s' of derivation '%s' must be a Boolean", name, + drvPath); + } + return i->get(); + } else { auto i = drv.env.find(name); if (i == drv.env.end()) { return def; - } else { - return i->second == "1"; } + return i->second == "1"; } } @@ -67,30 +65,28 @@ std::optional ParsedDerivation::getStringsAttr( auto i = structuredAttrs->find(name); if (i == structuredAttrs->end()) { return {}; - } else { - if (!i->is_array()) { + } + if (!i->is_array()) { + throw Error("attribute '%s' of derivation '%s' must be a list of strings", + name, drvPath); + } + Strings res; + for (const auto& j : *i) { + if (!j.is_string()) { throw Error( "attribute '%s' of derivation '%s' must be a list of strings", name, drvPath); } - Strings res; - for (const auto& j : *i) { - if (!j.is_string()) { - throw Error( - "attribute '%s' of derivation '%s' must be a list of strings", - name, drvPath); - } - res.push_back(j.get()); - } - return res; + res.push_back(j.get()); } + return res; + } else { auto i = drv.env.find(name); if (i == drv.env.end()) { return {}; - } else { - return tokenizeString(i->second); } + return tokenizeString(i->second); } } @@ -104,12 +100,13 @@ StringSet ParsedDerivation::getRequiredSystemFeatures() const { bool ParsedDerivation::canBuildLocally() const { if (drv.platform != settings.thisSystem.get() && - !settings.extraPlatforms.get().count(drv.platform) && !drv.isBuiltin()) { + (settings.extraPlatforms.get().count(drv.platform) == 0u) && + !drv.isBuiltin()) { return false; } for (auto& feature : getRequiredSystemFeatures()) { - if (!settings.systemFeatures.get().count(feature)) { + if (settings.systemFeatures.get().count(feature) == 0u) { return false; } } -- cgit 1.4.1