diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-14 07:02:49 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-14 13:50:54 +0000 |
commit | 8ab0d17f86ed4f4680f2c3237c4b5dd9937b3adb (patch) | |
tree | 9929749bc00456ea07eeb82372258787fe9178f6 /document | |
parent | 6d09bcb10d27f3980547cd5ea24cefdd6e115ee1 (diff) |
use std::move instead of swap to reduce simplify strange interfaces.
Diffstat (limited to 'document')
5 files changed, 29 insertions, 40 deletions
diff --git a/document/src/vespa/document/base/documentid.cpp b/document/src/vespa/document/base/documentid.cpp index c3ba8fea29d..3d5657d093c 100644 --- a/document/src/vespa/document/base/documentid.cpp +++ b/document/src/vespa/document/base/documentid.cpp @@ -37,6 +37,10 @@ DocumentId::DocumentId(const IdString& id) { } +DocumentId::DocumentId(const DocumentId & rhs) = default; +DocumentId & DocumentId::operator = (const DocumentId & rhs) = default; +DocumentId::~DocumentId() = default; + vespalib::string DocumentId::toString() const { return _id->toString(); diff --git a/document/src/vespa/document/base/documentid.h b/document/src/vespa/document/base/documentid.h index a4b01cdad82..d395b751011 100644 --- a/document/src/vespa/document/base/documentid.h +++ b/document/src/vespa/document/base/documentid.h @@ -37,6 +37,11 @@ public: DocumentId(); DocumentId(vespalib::nbostream & os); explicit DocumentId(const IdString& id); + DocumentId(DocumentId && rhs) = default; + DocumentId & operator = (DocumentId && rhs) = default; + DocumentId(const DocumentId & rhs); + DocumentId & operator = (const DocumentId & rhs); + ~DocumentId() override; /** * Parse the given document identifier given as string, and create an * identifier object from it. diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index 1bcee490378..4ff4d3a2143 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -3,7 +3,6 @@ #include "document.h" #include <vespa/document/datatype/documenttype.h> #include <vespa/vespalib/util/crc.h> -#include <vespa/document/repo/fixedtyperepo.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/document/serialization/vespadocumentserializer.h> @@ -64,13 +63,7 @@ Document::Document() _fields.setDocumentType(getType()); } -Document::Document(const Document& other) - : StructuredFieldValue(other), - _id(other._id), - _fields(other._fields), - _lastModified(other._lastModified) -{ -} +Document::Document(const Document& other) = default; Document::Document(const DataType &type, const DocumentId& documentId) : StructuredFieldValue(verifyDocumentType(&type)), @@ -84,18 +77,16 @@ Document::Document(const DataType &type, const DocumentId& documentId) } } -Document::Document(const DataType &type, DocumentId& documentId, bool iWillAllowSwap) +Document::Document(const DataType &type, DocumentId && documentId) : StructuredFieldValue(verifyDocumentType(&type)), - _id(), + _id(std::move(documentId)), _fields(getType().getFieldsType()), _lastModified(0) { - (void) iWillAllowSwap; _fields.setDocumentType(getType()); - if (documentId.hasDocType() && (documentId.getDocType() != type.getName())) { - throwTypeMismatch(type.getName(), documentId.getDocType()); + if (_id.hasDocType() && (_id.getDocType() != type.getName())) { + throwTypeMismatch(type.getName(), _id.getDocType()); } - _id.swap(documentId); } Document::Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, const DataType *anticipatedType) @@ -148,8 +139,7 @@ Document::Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer& deserializeBody(repo, body); } -Document::~Document() { -} +Document::~Document() = default; void Document::swap(Document & rhs) @@ -165,14 +155,7 @@ Document::getType() const { return static_cast<const DocumentType &>(StructuredFieldValue::getType()); } -Document& Document::operator=(const Document& doc) -{ - StructuredFieldValue::operator=(doc); - _id = doc._id; - _fields = doc._fields; - _lastModified = doc._lastModified; - return *this; -} +Document& Document::operator=(const Document& doc) = default; void Document::clear() @@ -210,7 +193,7 @@ Document::getDocTypeFromSerialized(const DocumentTypeRepo& repo, ByteBuffer& buf int position = buf.getPos(); DocumentId retVal; - const DocumentType *docType(deserializeDocHeaderAndType(repo, buf, retVal, NULL)); + const DocumentType *docType(deserializeDocHeaderAndType(repo, buf, retVal, nullptr)); buf.setPos(position); return docType; @@ -221,7 +204,7 @@ Document::assign(const FieldValue& value) { /// \todo TODO (was warning): This type checking doesnt work with the way assign is used. // if (*value.getDataType() == *_type) { - const Document& other(dynamic_cast<const Document&>(value)); + auto & other(dynamic_cast<const Document&>(value)); return operator=(other); // } // return FieldValue::assign(value); // Generates exception @@ -234,7 +217,7 @@ Document::compare(const FieldValue& other) const if (diff != 0) { return diff; } - const Document& doc(static_cast<const Document&>(other)); + auto & doc(static_cast<const Document&>(other)); vespalib::string id1 = _id.toString(); vespalib::string id2 = doc._id.toString(); if (id1 != id2) { @@ -309,9 +292,9 @@ Document::deserializeDocHeaderAndType( int16_t docTypeVersion; // version not supported anymore buffer.getShortNetwork(docTypeVersion); } - const DocumentType *docTypeNew = 0; + const DocumentType *docTypeNew = nullptr; - if (! ((docType != NULL) && (docType->getName() == docTypeName))) { + if (! ((docType != nullptr) && (docType->getName() == docTypeName))) { docTypeNew = repo.getDocumentType(docTypeName); if (!docTypeNew) { throw DocumentTypeNotFoundException(docTypeName, VESPA_STRLOC); diff --git a/document/src/vespa/document/fieldvalue/document.h b/document/src/vespa/document/fieldvalue/document.h index ebbe01958b8..e5a8a9ba368 100644 --- a/document/src/vespa/document/fieldvalue/document.h +++ b/document/src/vespa/document/fieldvalue/document.h @@ -40,15 +40,15 @@ public: Document(); Document(const Document&); Document(const DataType &, const DocumentId&); - Document(const DataType &, DocumentId &, bool iWillAllowSwap); - Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, const DataType *anticipatedType = 0); - Document(const DocumentTypeRepo& repo, vespalib::nbostream& stream, const DataType *anticipatedType = 0); + Document(const DataType &, DocumentId &&); + Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, const DataType *anticipatedType = nullptr); + Document(const DocumentTypeRepo& repo, vespalib::nbostream& stream, const DataType *anticipatedType = nullptr); /** Constructor to deserialize only document and type from a buffer. Only relevant if includeContent is false. */ Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, bool includeContent, const DataType *anticipatedType); - Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer& body, const DataType *anticipatedType = 0); - ~Document(); + Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer& body, const DataType *anticipatedType = nullptr); + ~Document() override; void setRepo(const DocumentTypeRepo & repo); const DocumentTypeRepo * getRepo() const { return _fields.getRepo(); } @@ -126,7 +126,8 @@ public: size_t getSerializedSize() const; /** Undo fieldvalue's toXml override for document. */ - std::string toXml(const std::string& indent = "") const override; + std::string toXml() const { return toXml(""); } + std::string toXml(const std::string& indent) const override; bool empty() const override { return _fields.empty(); } @@ -142,10 +143,6 @@ private: FieldValue::UP getFieldValue(const Field& field) const override { return _fields.getValue(field); } bool getFieldValue(const Field& field, FieldValue& value) const override { return _fields.getValue(field, value); } - // Iterator implementation - class FieldIterator; - friend class FieldIterator; - StructuredIterator::UP getIterator(const Field* first) const override; static void deserializeDocHeader(ByteBuffer& buffer, DocumentId& id); diff --git a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp index a0eaa9d8154..5770de5f392 100644 --- a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp @@ -72,7 +72,7 @@ void VespaDocumentDeserializer::readDocument(Document &value) { LOG(spam, "content_code is %u", content_code); const DocumentType *type = readDocType(value.getType()); if (type) { - Document newDoc(*type, value.getId(), true); + Document newDoc(*type, std::move(value.getId())); value.swap(newDoc); } value.setRepo(_repo.getDocumentTypeRepo()); |