From 0074fd7b101a9415fa6f6c5311f307cd311508f1 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Fri, 11 Sep 2020 09:28:39 +0000 Subject: Use a move constructor to avoid expensive copy when not necessary. --- .../vespa/document/fieldvalue/predicatefieldvalue.cpp | 17 +++++++++++------ .../src/vespa/document/fieldvalue/predicatefieldvalue.h | 6 ++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/document/src/vespa/document/fieldvalue/predicatefieldvalue.cpp b/document/src/vespa/document/fieldvalue/predicatefieldvalue.cpp index 68331a50262..6766f794141 100644 --- a/document/src/vespa/document/fieldvalue/predicatefieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/predicatefieldvalue.cpp @@ -34,9 +34,10 @@ PredicateFieldValue::PredicateFieldValue(const PredicateFieldValue &rhs) inject(rhs._slime->get(), SlimeInserter(*_slime)); } -PredicateFieldValue::~PredicateFieldValue() { } +PredicateFieldValue::~PredicateFieldValue() = default; -FieldValue &PredicateFieldValue::assign(const FieldValue &rhs) { +FieldValue & +PredicateFieldValue::assign(const FieldValue &rhs) { if (rhs.inherits(PredicateFieldValue::classId)) { operator=(static_cast(rhs)); return *this; @@ -47,7 +48,8 @@ FieldValue &PredicateFieldValue::assign(const FieldValue &rhs) { } } -PredicateFieldValue &PredicateFieldValue::operator=(const PredicateFieldValue &rhs) +PredicateFieldValue & +PredicateFieldValue::operator=(const PredicateFieldValue &rhs) { _slime = std::make_unique(); inject(rhs._slime->get(), SlimeInserter(*_slime)); @@ -55,18 +57,21 @@ PredicateFieldValue &PredicateFieldValue::operator=(const PredicateFieldValue &r return *this; } -int PredicateFieldValue::compare(const FieldValue&rhs) const { +int +PredicateFieldValue::compare(const FieldValue&rhs) const { int diff = FieldValue::compare(rhs); if (diff != 0) return diff; const PredicateFieldValue &o = static_cast(rhs); return Predicate::compare(*_slime, *o._slime); } -void PredicateFieldValue::printXml(XmlOutputStream& out) const { +void +PredicateFieldValue::printXml(XmlOutputStream& out) const { out << XmlContent(PredicatePrinter::print(*_slime)); } -void PredicateFieldValue::print(std::ostream& out, bool, const std::string&) const { +void +PredicateFieldValue::print(std::ostream& out, bool, const std::string&) const { out << PredicatePrinter::print(*_slime) << "\n"; } diff --git a/document/src/vespa/document/fieldvalue/predicatefieldvalue.h b/document/src/vespa/document/fieldvalue/predicatefieldvalue.h index e0df3a38353..7154affc9b0 100644 --- a/document/src/vespa/document/fieldvalue/predicatefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/predicatefieldvalue.h @@ -13,13 +13,15 @@ class PredicateFieldValue : public FieldValue { std::unique_ptr _slime; bool _altered; + PredicateFieldValue & operator=(const PredicateFieldValue &rhs); public: PredicateFieldValue(); PredicateFieldValue(std::unique_ptr s); PredicateFieldValue(const PredicateFieldValue &rhs); - ~PredicateFieldValue(); + PredicateFieldValue(PredicateFieldValue && rhs) noexcept = default; + ~PredicateFieldValue() override; - PredicateFieldValue &operator=(const PredicateFieldValue &rhs); + PredicateFieldValue & operator=(PredicateFieldValue && rhs) noexcept = default; void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } -- cgit v1.2.3