diff options
-rw-r--r-- | messagebus/src/vespa/messagebus/routing/routingnode.cpp | 6 | ||||
-rw-r--r-- | vdslib/src/vespa/vdslib/distribution/distribution.cpp | 26 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/trace/trace.cpp | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/trace/tracenode.cpp | 70 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/trace/tracenode.h | 8 |
5 files changed, 45 insertions, 67 deletions
diff --git a/messagebus/src/vespa/messagebus/routing/routingnode.cpp b/messagebus/src/vespa/messagebus/routing/routingnode.cpp index fc0845e5316..b5b99ea43c2 100644 --- a/messagebus/src/vespa/messagebus/routing/routingnode.cpp +++ b/messagebus/src/vespa/messagebus/routing/routingnode.cpp @@ -174,7 +174,7 @@ RoutingNode::addError(uint32_t code, const string &msg) void RoutingNode::addError(const Error &err) { - if (_reply.get() != nullptr) { + if (_reply) { _reply->getTrace().swap(_trace); _reply->addError(err); _reply->getTrace().swap(_trace); @@ -186,9 +186,9 @@ RoutingNode::addError(const Error &err) void RoutingNode::setReply(Reply::UP reply) { - if (reply.get() != nullptr) { + if (reply) { _shouldRetry = _resender != nullptr && _resender->shouldRetry(*reply); - _trace.getRoot().addChild(reply->getTrace().getRoot()); + _trace.getRoot().addChild(std::move(reply->getTrace().getRoot())); reply->getTrace().clear(); } _reply = std::move(reply); diff --git a/vdslib/src/vespa/vdslib/distribution/distribution.cpp b/vdslib/src/vespa/vdslib/distribution/distribution.cpp index ff84687210d..9b31d10d8e8 100644 --- a/vdslib/src/vespa/vdslib/distribution/distribution.cpp +++ b/vdslib/src/vespa/vdslib/distribution/distribution.cpp @@ -549,8 +549,7 @@ Distribution::getIdealNodes(const NodeType& nodeType, uint32_t seed; if (nodeType == NodeType::STORAGE) { seed = getStorageSeed(bucket, clusterState); - getIdealGroups(bucket, clusterState, *_nodeGraph, redundancy, - _groupDistribution); + getIdealGroups(bucket, clusterState, *_nodeGraph, redundancy, _groupDistribution); } else { seed = getDistributorSeed(bucket, clusterState); const Group* group(getIdealDistributorGroup(bucket, clusterState, *_nodeGraph)); @@ -566,8 +565,7 @@ Distribution::getIdealNodes(const NodeType& nodeType, uint32_t randomIndex = 0; for (uint32_t i=0, n=_groupDistribution.size(); i<n; ++i) { uint16_t groupRedundancy(_groupDistribution[i]._redundancy); - const std::vector<uint16_t>& nodes( - _groupDistribution[i]._group->getNodes()); + const std::vector<uint16_t>& nodes(_groupDistribution[i]._group->getNodes()); // Create temporary place to hold results. Use double linked list // for cheap access to back(). Stuff in redundancy fake entries to // avoid needing to check size during iteration. @@ -576,15 +574,11 @@ Distribution::getIdealNodes(const NodeType& nodeType, // Verify that the node is legal target before starting to grab // random number. Helps worst case of having to start new random // seed if the node that is out of order is illegal anyways. - const NodeState& nodeState( - clusterState.getNodeState(Node(nodeType, nodes[j]))); + const NodeState& nodeState(clusterState.getNodeState(Node(nodeType, nodes[j]))); if (!nodeState.getState().oneOf(upStates)) continue; if (nodeState.isAnyDiskDown()) { - uint16_t idealDiskIndex(getIdealDisk( - nodeState, nodes[j], bucket, IDEAL_DISK_EVEN_IF_DOWN)); - if (nodeState.getDiskState(idealDiskIndex).getState() - != State::UP) - { + uint16_t idealDiskIndex(getIdealDisk(nodeState, nodes[j], bucket, IDEAL_DISK_EVEN_IF_DOWN)); + if (nodeState.getDiskState(idealDiskIndex).getState() != State::UP) { continue; } } @@ -611,8 +605,7 @@ Distribution::getIdealNodes(const NodeType& nodeType, it != tmpResults.end(); ++it) { if (score > it->_score) { - tmpResults.insert(it, ScoredNode( - nodes[j], nodeState.getReliability(), score)); + tmpResults.insert(it, ScoredNode(nodes[j], nodeState.getReliability(), score)); break; } } @@ -620,10 +613,9 @@ Distribution::getIdealNodes(const NodeType& nodeType, } } trimResult(tmpResults, groupRedundancy); - for (std::list<ScoredNode>::iterator it = tmpResults.begin(); - it != tmpResults.end(); ++it) - { - resultNodes.push_back(it->_index); + resultNodes.reserve(resultNodes.size() + tmpResults.size()); + for (const auto & scored : tmpResults) { + resultNodes.push_back(scored._index); } } } diff --git a/vespalib/src/vespa/vespalib/trace/trace.cpp b/vespalib/src/vespa/vespalib/trace/trace.cpp index 6253b57b0c5..4d0ecc0e9df 100644 --- a/vespalib/src/vespa/vespalib/trace/trace.cpp +++ b/vespalib/src/vespa/vespalib/trace/trace.cpp @@ -20,7 +20,7 @@ Trace::Trace(uint32_t level) : // empty } -Trace::~Trace() { } +Trace::~Trace() = default; Trace & Trace::clear() diff --git a/vespalib/src/vespa/vespalib/trace/tracenode.cpp b/vespalib/src/vespa/vespalib/trace/tracenode.cpp index 79497ec5ca1..495dfc618e7 100644 --- a/vespalib/src/vespa/vespalib/trace/tracenode.cpp +++ b/vespalib/src/vespa/vespalib/trace/tracenode.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/trace/tracenode.h> -#include <vespa/vespalib/trace/tracevisitor.h> +#include "tracenode.h" +#include "tracevisitor.h" #include <algorithm> #include <vespa/log/log.h> @@ -41,7 +41,7 @@ struct Cmp { TraceNode::TraceNode() : - _parent(NULL), + _parent(nullptr), _strict(true), _hasNote(false), _note(""), @@ -50,7 +50,7 @@ TraceNode::TraceNode() : { } TraceNode::TraceNode(const TraceNode &rhs) : - _parent(NULL), + _parent(nullptr), _strict(rhs._strict), _hasNote(rhs._hasNote), _note(rhs._note), @@ -62,10 +62,10 @@ TraceNode::TraceNode(const TraceNode &rhs) : TraceNode & TraceNode::operator =(const TraceNode &) = default; -TraceNode::~TraceNode() { } +TraceNode::~TraceNode() = default; TraceNode::TraceNode(const string ¬e, int64_t timestamp) : - _parent(NULL), + _parent(nullptr), _strict(true), _hasNote(true), _note(note), @@ -74,7 +74,7 @@ TraceNode::TraceNode(const string ¬e, int64_t timestamp) : { } TraceNode::TraceNode(int64_t timestamp) : - _parent(NULL), + _parent(nullptr), _strict(true), _hasNote(false), _note(""), @@ -90,15 +90,11 @@ TraceNode::swap(TraceNode &other) std::swap(_hasNote, other._hasNote); _note.swap(other._note); _children.swap(other._children); - for (std::vector<TraceNode>::iterator it = _children.begin(); - it != _children.end(); ++it) - { - it->_parent = this; + for (auto & child : _children) { + child._parent = this; } - for (std::vector<TraceNode>::iterator it = other._children.begin(); - it != other._children.end(); ++it) - { - it->_parent = &other; + for (auto & child : other._children) { + child._parent = &other; } std::swap(_timestamp, other._timestamp); return *this; @@ -107,7 +103,7 @@ TraceNode::swap(TraceNode &other) TraceNode & TraceNode::clear() { - _parent = NULL; + _parent = nullptr; _strict = true; _hasNote = false; _note.clear(); @@ -120,10 +116,8 @@ TraceNode & TraceNode::sort() { if (!isLeaf()) { - for (std::vector<TraceNode>::iterator it = _children.begin(); - it != _children.end(); ++it) - { - it->sort(); + for (auto & child : _children) { + child.sort(); } if (!isStrict()) { std::sort(_children.begin(), _children.end(), Cmp()); @@ -140,15 +134,13 @@ TraceNode::compact() } std::vector<TraceNode> tmp; tmp.swap(_children); - for (std::vector<TraceNode>::iterator it = tmp.begin(); - it != tmp.end(); ++it) + for (auto & child : tmp) { - TraceNode &child = *it; child.compact(); if (child.isEmpty()) { // ignore } else if (child.isLeaf()) { - addChild(*it); + addChild(child); } else if (_strict == child._strict) { addChildren(child._children); } else if (child.getNumChildren() == 1) { @@ -161,7 +153,7 @@ TraceNode::compact() addChildren(grandChild._children); } } else { - addChild(*it); + addChild(child); } } return *this; @@ -194,21 +186,19 @@ TraceNode::addChild(const string ¬e, int64_t timestamp) } TraceNode & -TraceNode::addChild(const TraceNode &child) +TraceNode::addChild(TraceNode child) { LOG_ASSERT(!_hasNote); - _children.push_back(child); + _children.emplace_back(std::move(child)); _children.back()._parent = this; return *this; } TraceNode & -TraceNode::addChildren(const std::vector<TraceNode> &children) +TraceNode::addChildren(std::vector<TraceNode> children) { - for (std::vector<TraceNode>::const_iterator it = children.begin(); - it != children.end(); ++it) - { - addChild(*it); + for (auto & child : children) { + addChild(std::move(child)); } return *this; } @@ -236,10 +226,8 @@ TraceNode::writeString(string &dst, size_t indent, size_t limit) const } string name = isStrict() ? "trace" : "fork"; dst.append(pre).append("<").append(name).append(">\n"); - for (std::vector<TraceNode>::const_iterator it = _children.begin(); - it != _children.end(); ++it) - { - if (!it->writeString(dst, indent + 4, limit)) { + for (const auto & child : _children) { + if (!child.writeString(dst, indent + 4, limit)) { return false; } } @@ -266,10 +254,8 @@ TraceNode::encode() const ret.append("]"); } else { ret.append(_strict ? "(" : "{"); - for (std::vector<TraceNode>::const_iterator it = _children.begin(); - it != _children.end(); ++it) - { - ret.append(it->encode()); + for (const auto & child : _children) { + ret.append(child.encode()); } ret.append(_strict ? ")" : "}"); } @@ -349,8 +335,8 @@ TraceNode::accept(TraceVisitor & visitor) const return visitor; } visitor.entering(*this); - for (auto it(_children.begin()), mt(_children.end()); it != mt; it++) { - it->accept(visitor); + for (auto & child : _children) { + child.accept(visitor); } visitor.leaving(*this); return visitor; diff --git a/vespalib/src/vespa/vespalib/trace/tracenode.h b/vespalib/src/vespa/vespalib/trace/tracenode.h index 86fedbcd3e4..52dc96f04e2 100644 --- a/vespalib/src/vespa/vespalib/trace/tracenode.h +++ b/vespalib/src/vespa/vespalib/trace/tracenode.h @@ -49,8 +49,8 @@ public: explicit TraceNode(int64_t timestamp); TraceNode & operator =(const TraceNode &); - TraceNode(TraceNode &&) = default; - TraceNode & operator =(TraceNode &&) = default; + TraceNode(TraceNode &&) noexcept = default; + TraceNode & operator =(TraceNode &&) noexcept = default; ~TraceNode(); /** @@ -197,7 +197,7 @@ public: * @param child The child to add. * @return This, to allow chaining. */ - TraceNode &addChild(const TraceNode &child); + TraceNode &addChild(TraceNode child); /** * Adds a list of child nodes to this. @@ -205,7 +205,7 @@ public: * @param children The children to add. * @return This, to allow chaining. */ - TraceNode &addChildren(const std::vector<TraceNode> &children); + TraceNode &addChildren(std::vector<TraceNode> children); /** * Generate a non-parseable, human-readable string representation of |