diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-04-06 10:25:02 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-04-06 10:25:02 +0000 |
commit | e1696ca01338d1df06fa12452544c3e62ac3267c (patch) | |
tree | e8eac1330843d33ebd58bebe2ba84db5695c0871 /document | |
parent | 3c4cddd0b08666e497996e7f5b499e5a86fc68eb (diff) |
Reduce use of CloneablePtr
Diffstat (limited to 'document')
-rw-r--r-- | document/src/vespa/document/base/fieldpath.cpp | 37 | ||||
-rw-r--r-- | document/src/vespa/document/base/fieldpath.h | 37 | ||||
-rw-r--r-- | document/src/vespa/document/fieldvalue/mapfieldvalue.cpp | 6 |
3 files changed, 42 insertions, 38 deletions
diff --git a/document/src/vespa/document/base/fieldpath.cpp b/document/src/vespa/document/base/fieldpath.cpp index fcac59847cb..01855af55eb 100644 --- a/document/src/vespa/document/base/fieldpath.cpp +++ b/document/src/vespa/document/base/fieldpath.cpp @@ -11,7 +11,6 @@ using vespalib::make_string; namespace document { -FieldPathEntry::FieldPathEntry(const FieldPathEntry &) = default; FieldPathEntry::~FieldPathEntry() = default; FieldPathEntry::FieldPathEntry() : @@ -46,7 +45,7 @@ FieldPathEntry::FieldPathEntry(const Field &fieldRef) : _lookupIndex(0), _lookupKey(), _variableName(), - _fillInVal(fieldRef.createValue().release()) + _fillInVal(fieldRef.createValue()) { } FieldPathEntry::FieldPathEntry(const DataType & dataType, const DataType& fillType, @@ -56,13 +55,24 @@ FieldPathEntry::FieldPathEntry(const DataType & dataType, const DataType& fillTy _field(), _dataType(&dataType), _lookupIndex(0), - _lookupKey(lookupKey.release()), + _lookupKey(std::move(lookupKey)), _variableName(), _fillInVal() { setFillValue(fillType); } +FieldPathEntry::FieldPathEntry(const FieldPathEntry &rhs) + : _type(rhs._type), + _name(rhs._name), + _field(rhs._field), + _dataType(rhs._dataType), + _lookupIndex(rhs._lookupIndex), + _lookupKey(rhs._lookupKey ? rhs._lookupKey->clone() : nullptr), + _variableName(rhs._variableName), + _fillInVal(rhs._fillInVal ? rhs._fillInVal->clone() : nullptr) +{} + void FieldPathEntry::setFillValue(const DataType & dataType) { @@ -82,7 +92,7 @@ FieldPathEntry::setFillValue(const DataType & dataType) } } if (dt->isPrimitive()) { - _fillInVal.reset(dt->createFieldValue().release()); + _fillInVal = dt->createFieldValue(); } } @@ -123,7 +133,7 @@ FieldPathEntry::getDataType() const FieldValue::UP FieldPathEntry::stealFieldValueToSet() const { - return FieldValue::UP(_fillInVal.release()); + return std::move(_fillInVal); } vespalib::string @@ -171,17 +181,20 @@ FieldPathEntry::parseKey(vespalib::stringref & key) return v; } -FieldPath::FieldPath() - : _path() -{ } - -FieldPath::FieldPath(const FieldPath &) = default; -FieldPath & FieldPath::operator=(const FieldPath &) = default; +FieldPath::FieldPath() = default; FieldPath::~FieldPath() = default; +FieldPath::FieldPath(const FieldPath & rhs) + : _path() +{ + _path.reserve(rhs.size()); + for (const auto & e : rhs._path) { + _path.emplace_back(std::make_unique<FieldPathEntry>(*e)); + } +} FieldPath::iterator FieldPath::insert(iterator pos, std::unique_ptr<FieldPathEntry> entry) { - return _path.insert(pos, vespalib::CloneablePtr<FieldPathEntry>(entry.release())); + return _path.insert(pos, std::move(entry)); } void FieldPath::push_back(std::unique_ptr<FieldPathEntry> entry) { _path.emplace_back(entry.release()); } void FieldPath::pop_back() { _path.pop_back(); } diff --git a/document/src/vespa/document/base/fieldpath.h b/document/src/vespa/document/base/fieldpath.h index a79e4595a61..c2db3276fb4 100644 --- a/document/src/vespa/document/base/fieldpath.h +++ b/document/src/vespa/document/base/fieldpath.h @@ -2,7 +2,6 @@ #pragma once #include "field.h" -#include <vespa/vespalib/util/memory.h> namespace document { @@ -23,13 +22,12 @@ public: VARIABLE, NONE }; - using FieldValueCP = vespalib::CloneablePtr<FieldValue>; - FieldPathEntry(); - FieldPathEntry(FieldPathEntry &&) = default; - FieldPathEntry & operator=(FieldPathEntry &&) = default; + FieldPathEntry(FieldPathEntry &&) noexcept = default; + FieldPathEntry & operator=(FieldPathEntry &&) noexcept = default; FieldPathEntry(const FieldPathEntry &); + FieldPathEntry & operator=(const FieldPathEntry &) = delete; /** Creates a field path entry for a struct field lookup. @@ -58,8 +56,6 @@ public: */ FieldPathEntry(const DataType & dataType, vespalib::stringref variableName); - FieldPathEntry * clone() const { return new FieldPathEntry(*this); } - Type getType() const { return _type; } const vespalib::string & getName() const { return _name; } @@ -70,7 +66,7 @@ public: uint32_t getIndex() const { return _lookupIndex; } - const FieldValueCP & getLookupKey() const { return _lookupKey; } + FieldValue & getLookupKey() const { return *_lookupKey; } const vespalib::string& getVariableName() const { return _variableName; } @@ -85,20 +81,20 @@ public: static vespalib::string parseKey(vespalib::stringref & key); private: void setFillValue(const DataType & dataType); - Type _type; - vespalib::string _name; - Field _field; - const DataType * _dataType; - uint32_t _lookupIndex; - FieldValueCP _lookupKey; - vespalib::string _variableName; - mutable FieldValueCP _fillInVal; + Type _type; + vespalib::string _name; + Field _field; + const DataType * _dataType; + uint32_t _lookupIndex; + std::unique_ptr<FieldValue> _lookupKey; + vespalib::string _variableName; + mutable std::unique_ptr<FieldValue> _fillInVal; }; //typedef std::deque<FieldPathEntry> FieldPath; // Facade over FieldPathEntry container that exposes cloneability class FieldPath { - typedef std::vector<vespalib::CloneablePtr<FieldPathEntry>> Container; + typedef std::vector<std::unique_ptr<FieldPathEntry>> Container; public: typedef Container::reference reference; typedef Container::const_reference const_reference; @@ -110,16 +106,11 @@ public: FieldPath(); FieldPath(const FieldPath &); - FieldPath & operator=(const FieldPath &); + FieldPath & operator=(const FieldPath &) = delete; FieldPath(FieldPath &&) noexcept = default; FieldPath & operator=(FieldPath &&) noexcept = default; ~FieldPath(); - template <typename InputIterator> - FieldPath(InputIterator first, InputIterator last) - : _path(first, last) - { } - iterator insert(iterator pos, std::unique_ptr<FieldPathEntry> entry); void push_back(std::unique_ptr<FieldPathEntry> entry); diff --git a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp index 33ce4357f03..7385b261339 100644 --- a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp @@ -421,9 +421,9 @@ MapFieldValue::iterateNestedImpl(PathRange nested, case FieldPathEntry::MAP_KEY: { LOG(spam, "MAP_KEY"); - const_iterator iter = find(*fpe.getLookupKey()); + const_iterator iter = find(fpe.getLookupKey()); if (iter != end()) { - wasModified = checkAndRemove(*fpe.getLookupKey(), + wasModified = checkAndRemove(fpe.getLookupKey(), iter->second->iterateNested(nested.next(), handler), wasModified, keysToRemove); } else if (handler.createMissingPath()) { @@ -431,7 +431,7 @@ MapFieldValue::iterateNestedImpl(PathRange nested, FieldValue::UP val = getMapType().getValueType().createFieldValue(); ModificationStatus status = val->iterateNested(nested.next(), handler); if (status == ModificationStatus::MODIFIED) { - const_cast<MapFieldValue&>(*this).put(FieldValue::UP(fpe.getLookupKey()->clone()), std::move(val)); + const_cast<MapFieldValue&>(*this).put(FieldValue::UP(fpe.getLookupKey().clone()), std::move(val)); return status; } } |