From 463ef8dd6bc4c48f7de43eb79b91a3dc51da7a15 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 7 Apr 2022 09:17:38 +0000 Subject: Use std::move in select preparations. --- .../vespa/document/fieldvalue/iteratorhandler.h | 2 +- .../src/vespa/document/fieldvalue/variablemap.cpp | 4 ++-- document/src/vespa/document/select/branch.cpp | 28 +++++++++------------- document/src/vespa/document/select/compare.cpp | 14 ++++------- document/src/vespa/document/select/value.cpp | 16 +++++-------- document/src/vespa/document/select/valuenodes.cpp | 2 +- .../src/vespa/document/update/fieldpathupdate.cpp | 4 ++-- 7 files changed, 28 insertions(+), 42 deletions(-) (limited to 'document') diff --git a/document/src/vespa/document/fieldvalue/iteratorhandler.h b/document/src/vespa/document/fieldvalue/iteratorhandler.h index bef013e1845..2f7b5d522e9 100644 --- a/document/src/vespa/document/fieldvalue/iteratorhandler.h +++ b/document/src/vespa/document/fieldvalue/iteratorhandler.h @@ -77,7 +77,7 @@ public: void setArrayIndex(uint32_t index) { _arrayIndexStack.back() = index; } ModificationStatus modify(FieldValue &fv) { return doModify(fv); } fieldvalue::VariableMap &getVariables() { return _variables; } - void setVariables(const fieldvalue::VariableMap &vars) { _variables = vars; } + void setVariables(fieldvalue::VariableMap vars) { _variables = std::move(vars); } virtual bool createMissingPath() const { return false; } private: virtual bool onComplex(const Content &fv) { diff --git a/document/src/vespa/document/fieldvalue/variablemap.cpp b/document/src/vespa/document/fieldvalue/variablemap.cpp index 481e5288a24..655b156fe30 100644 --- a/document/src/vespa/document/fieldvalue/variablemap.cpp +++ b/document/src/vespa/document/fieldvalue/variablemap.cpp @@ -11,8 +11,8 @@ IndexValue::IndexValue(int index_) : index(index_), key() {} bool IndexValue::operator==(const IndexValue& other) const { - if (key.get() != NULL) { - if (other.key.get() != NULL && *key == *other.key) { + if (key) { + if (other.key && *key == *other.key) { return true; } return false; diff --git a/document/src/vespa/document/select/branch.cpp b/document/src/vespa/document/select/branch.cpp index bb08f0a5ba1..d8dc58edf20 100644 --- a/document/src/vespa/document/select/branch.cpp +++ b/document/src/vespa/document/select/branch.cpp @@ -12,8 +12,8 @@ And::And(std::unique_ptr left, std::unique_ptr right, const char* na _left(std::move(left)), _right(std::move(right)) { - assert(_left.get()); - assert(_right.get()); + assert(_left); + assert(_right); } @@ -39,11 +39,9 @@ namespace { ResultList traceAndValue(const T& value, std::ostream& out, const Node& leftNode, const Node& rightNode) { - ResultList left = leftNode.contains(value); - out << "And - Left branch returned " << left << ".\n"; - ResultList right = rightNode.contains(value); - out << "And - Right branch returned " << right << ".\n"; - return left && right; + out << "And - Left branch returned " << leftNode.contains(value) << ".\n"; + out << "And - Right branch returned " << rightNode.contains(value) << ".\n"; + return leftNode.contains(value) && rightNode.contains(value); } } @@ -85,11 +83,9 @@ namespace { ResultList traceOrValue(const T& value, std::ostream& out, const Node& leftNode, const Node& rightNode) { - ResultList left = leftNode.contains(value); - out << "Or - Left branch returned " << left << ".\n"; - ResultList right = rightNode.contains(value); - out << "Or - Right branch returned " << right << ".\n"; - return left || right; + out << "Or - Left branch returned " << leftNode.contains(value) << ".\n"; + out << "Or - Right branch returned " << rightNode.contains(value) << ".\n"; + return leftNode.contains(value) || rightNode.contains(value); } } @@ -124,13 +120,11 @@ Not::print(std::ostream& out, bool verbose, const std::string& indent) const namespace { template - ResultList traceNotValue(const T& value, std::ostream& out, - const Node& node) + ResultList traceNotValue(const T& value, std::ostream& out, const Node& node) { - ResultList result = node.contains(value); - out << "Not - Child returned " << result + out << "Not - Child returned " << node.contains(value) << ". Returning opposite.\n"; - return !result; + return !node.contains(value); } } diff --git a/document/src/vespa/document/select/compare.cpp b/document/src/vespa/document/select/compare.cpp index 1d792041c4e..36ef3b7cdbe 100644 --- a/document/src/vespa/document/select/compare.cpp +++ b/document/src/vespa/document/select/compare.cpp @@ -54,12 +54,10 @@ namespace { document::BucketId b( static_cast(bVal).getValue()); document::BucketId s( static_cast(nVal).getValue()); - ResultList resultList(Result::get(s.contains(b))); - if (op == FunctionOperator::NE) { - return !resultList; + return ! ResultList(Result::get(s.contains(b))); } - return resultList; + return ResultList(Result::get(s.contains(b))); } else { return ResultList(Result::Invalid); } @@ -87,11 +85,9 @@ namespace { document::BucketId s( static_cast(nVal).getValue()); - ResultList resultList(Result::get(s.contains(b))); - - if (op == FunctionOperator::NE) { - resultList = !resultList; - } + ResultList resultList = (op == FunctionOperator::NE) + ? !ResultList(Result::get(s.contains(b))) + : ResultList(Result::get(s.contains(b))); out << "Checked if " << b.toString() << " is "; if (op == FunctionOperator::NE) { out << "not "; } diff --git a/document/src/vespa/document/select/value.cpp b/document/src/vespa/document/select/value.cpp index e0a2bf84f09..aabd09b2558 100644 --- a/document/src/vespa/document/select/value.cpp +++ b/document/src/vespa/document/select/value.cpp @@ -2,6 +2,7 @@ #include "value.h" #include "operator.h" +#include "variablemap.h" #include #include #include @@ -45,8 +46,7 @@ InvalidValue::operator==(const Value&) const } void -InvalidValue::print(std::ostream& out, bool verbose, - const std::string& indent) const +InvalidValue::print(std::ostream& out, bool verbose, const std::string& indent) const { (void) verbose; (void) indent; out << "invalid"; @@ -123,8 +123,7 @@ StringValue::operator==(const Value& value) const } void -StringValue::print(std::ostream& out, bool verbose, - const std::string& indent) const +StringValue::print(std::ostream& out, bool verbose, const std::string& indent) const { (void) verbose; (void) indent; out << "\"" << _value << "\""; @@ -156,8 +155,7 @@ IntegerValue::operator==(const Value& value) const } void -IntegerValue::print(std::ostream& out, bool verbose, - const std::string& indent) const +IntegerValue::print(std::ostream& out, bool verbose, const std::string& indent) const { (void) verbose; (void) indent; out << _value << 'i'; @@ -189,8 +187,7 @@ FloatValue::operator==(const Value& value) const } void -FloatValue::print(std::ostream& out, bool verbose, - const std::string& indent) const +FloatValue::print(std::ostream& out, bool verbose, const std::string& indent) const { (void) verbose; (void) indent; out << _value << 'f'; @@ -312,8 +309,7 @@ ArrayValue::regexTrace(const Value& value, std::ostream& trace) const } void -ArrayValue::print(std::ostream& out, bool verbose, - const std::string& indent) const +ArrayValue::print(std::ostream& out, bool verbose, const std::string& indent) const { (void) verbose; (void) indent; out << ""; diff --git a/document/src/vespa/document/select/valuenodes.cpp b/document/src/vespa/document/select/valuenodes.cpp index cd66bac9635..2a9604e7f43 100644 --- a/document/src/vespa/document/select/valuenodes.cpp +++ b/document/src/vespa/document/select/valuenodes.cpp @@ -223,7 +223,7 @@ namespace { class IteratorHandler : public fieldvalue::IteratorHandler { public: IteratorHandler(); - ~IteratorHandler(); + ~IteratorHandler() override; bool hasSingleValue() const; std::unique_ptr stealSingleValue() &&; std::vector stealValues() &&; diff --git a/document/src/vespa/document/update/fieldpathupdate.cpp b/document/src/vespa/document/update/fieldpathupdate.cpp index 9267ff62e1b..5b47b48dd57 100644 --- a/document/src/vespa/document/update/fieldpathupdate.cpp +++ b/document/src/vespa/document/update/fieldpathupdate.cpp @@ -74,10 +74,10 @@ FieldPathUpdate::applyTo(Document& doc) const } else { std::unique_ptr whereClause = parseDocumentSelection(_originalWhereClause, *doc.getRepo()); select::ResultList results = whereClause->contains(doc); - for (select::ResultList::const_reverse_iterator i = results.rbegin(); i != results.rend(); ++i) { + for (auto i = results.rbegin(); i != results.rend(); ++i) { LOG(spam, "vars = %s", handler->getVariables().toString().c_str()); if (*i->second == select::Result::True) { - handler->setVariables(i->first); + handler->setVariables(std::move(i->first)); doc.iterateNested(path, *handler); } } -- cgit v1.2.3