From 190a32ada5a9d536d72462ef91b8d5322cc950e5 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 10 Aug 2023 20:17:55 +0000 Subject: Minor code health. --- .../vdslib/distribution/idealnodecalculator.h | 35 ++++++++++------------ .../distribution/idealnodecalculatorimpl.cpp | 9 +++--- 2 files changed, 20 insertions(+), 24 deletions(-) (limited to 'vdslib') diff --git a/vdslib/src/vespa/vdslib/distribution/idealnodecalculator.h b/vdslib/src/vespa/vdslib/distribution/idealnodecalculator.h index bc42df1b49c..4eb8f7e04ae 100644 --- a/vdslib/src/vespa/vdslib/distribution/idealnodecalculator.h +++ b/vdslib/src/vespa/vdslib/distribution/idealnodecalculator.h @@ -22,25 +22,20 @@ class ClusterState; * unneeded details, and make it easily printable. */ class IdealNodeList : public document::Printable { - std::vector _idealNodes; - public: - IdealNodeList(); + IdealNodeList() noexcept; ~IdealNodeList(); void push_back(const Node& node) { _idealNodes.push_back(node); } - const Node& operator[](uint32_t i) const { return _idealNodes[i]; } - uint32_t size() const { return _idealNodes.size(); } - bool contains(const Node& n) const { - for (uint32_t i=0; i<_idealNodes.size(); ++i) { - if (n == _idealNodes[i]) return true; - } - return false; + const Node& operator[](uint32_t i) const noexcept { return _idealNodes[i]; } + uint32_t size() const noexcept { return _idealNodes.size(); } + bool contains(const Node& n) const noexcept { + return indexOf(n) != 0xffff; } - uint16_t indexOf(const Node& n) const { + uint16_t indexOf(const Node& n) const noexcept { for (uint16_t i=0; i<_idealNodes.size(); ++i) { if (n == _idealNodes[i]) return i; } @@ -48,6 +43,8 @@ public: } void print(std::ostream& out, bool, const std::string &) const override; +private: + std::vector _idealNodes; }; /** @@ -64,17 +61,15 @@ public: virtual ~IdealNodeCalculator() = default; - virtual IdealNodeList getIdealNodes(const NodeType&, - const document::BucketId&, - UpStates upStates = UpInit) const = 0; + virtual IdealNodeList getIdealNodes(const NodeType&, const document::BucketId&, UpStates upStates = UpInit) const = 0; // Wrapper functions to make prettier call if nodetype is given. - IdealNodeList getIdealDistributorNodes(const document::BucketId& bucket, - UpStates upStates = UpInit) const - { return getIdealNodes(NodeType::DISTRIBUTOR, bucket, upStates); } - IdealNodeList getIdealStorageNodes(const document::BucketId& bucket, - UpStates upStates = UpInit) const - { return getIdealNodes(NodeType::STORAGE, bucket, upStates); } + IdealNodeList getIdealDistributorNodes(const document::BucketId& bucket, UpStates upStates = UpInit) const { + return getIdealNodes(NodeType::DISTRIBUTOR, bucket, upStates); + } + IdealNodeList getIdealStorageNodes(const document::BucketId& bucket, UpStates upStates = UpInit) const { + return getIdealNodes(NodeType::STORAGE, bucket, upStates); + } }; diff --git a/vdslib/src/vespa/vdslib/distribution/idealnodecalculatorimpl.cpp b/vdslib/src/vespa/vdslib/distribution/idealnodecalculatorimpl.cpp index da34ec4526a..86123f47d6f 100644 --- a/vdslib/src/vespa/vdslib/distribution/idealnodecalculatorimpl.cpp +++ b/vdslib/src/vespa/vdslib/distribution/idealnodecalculatorimpl.cpp @@ -8,7 +8,7 @@ namespace storage::lib { -IdealNodeList::IdealNodeList() = default; +IdealNodeList::IdealNodeList() noexcept = default; IdealNodeList::~IdealNodeList() = default; void @@ -63,9 +63,10 @@ IdealNodeCalculatorImpl::initUpStateMapping() { _upStates[UpInit] = "ui"; _upStates[UpInitMaintenance] = "uim"; for (uint32_t i=0; i<_upStates.size(); ++i) { - if (_upStates[i] == 0) throw vespalib::IllegalStateException( - "Failed to initialize up state. Code likely not updated " - "after another upstate was added.", VESPA_STRLOC); + if (_upStates[i] == 0) { + throw vespalib::IllegalStateException("Failed to initialize up state. Code likely not updated " + "after another upstate was added.", VESPA_STRLOC); + } } } -- cgit v1.2.3