summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-16 11:45:12 +0100
committerGitHub <noreply@github.com>2020-01-16 11:45:12 +0100
commitb324c19e007a7a57ba731ed72a01d35cd6937ed7 (patch)
treefd27f6cd58d35168a17c0ed4b7e9765457b19e10 /document
parent99eb3b5fe51397ec2fb29e2388e97c24a28ffb69 (diff)
parent6b816198bd0d8a518465c8015e6dc9ee40399cd2 (diff)
Merge pull request #11782 from vespa-engine/balder/bring-you-backing-buffer-along
Balder/bring your backing buffer along
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/documentidtest.cpp12
-rw-r--r--document/src/tests/documenttestcase.cpp3
-rw-r--r--document/src/tests/fieldvalue/referencefieldvalue_test.cpp4
-rw-r--r--document/src/vespa/document/base/documentid.cpp43
-rw-r--r--document/src/vespa/document/base/documentid.h17
-rw-r--r--document/src/vespa/document/base/idstring.cpp20
-rw-r--r--document/src/vespa/document/base/idstring.h3
-rw-r--r--document/src/vespa/document/fieldvalue/document.cpp82
-rw-r--r--document/src/vespa/document/fieldvalue/document.h23
-rw-r--r--document/src/vespa/document/fieldvalue/fieldvalue.h2
-rw-r--r--document/src/vespa/document/fieldvalue/referencefieldvalue.cpp7
-rw-r--r--document/src/vespa/document/fieldvalue/structfieldvalue.cpp29
-rw-r--r--document/src/vespa/document/fieldvalue/structfieldvalue.h6
-rw-r--r--document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp9
-rw-r--r--document/src/vespa/document/fieldvalue/structuredfieldvalue.h13
-rw-r--r--document/src/vespa/document/serialization/vespadocumentdeserializer.cpp6
16 files changed, 99 insertions, 180 deletions
diff --git a/document/src/tests/documentidtest.cpp b/document/src/tests/documentidtest.cpp
index a6255cc148a..d3f6e8a8fcd 100644
--- a/document/src/tests/documentidtest.cpp
+++ b/document/src/tests/documentidtest.cpp
@@ -44,16 +44,8 @@ TEST(DocumentIdTest, generateJavaComplianceFile)
TEST(DocumentIdTest, testOutput)
{
DocumentId id("id:ns:news::crawler:http://www.yahoo.com");
-
- std::ostringstream ost;
- ost << id;
- std::string expected("id:ns:news::crawler:http://www.yahoo.com");
- EXPECT_EQ(expected, ost.str());
-
- EXPECT_EQ(vespalib::string(expected), id.toString());
-
- expected = "DocumentId(id = id:ns:news::crawler:http://www.yahoo.com, gid(0xa516a5abd7c7fa26944b72f7))";
- EXPECT_EQ(expected, static_cast<Printable&>(id).toString(true));
+ vespalib::string expected("id:ns:news::crawler:http://www.yahoo.com");
+ EXPECT_EQ(expected, id.toString());
}
namespace {
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp
index fa59358f6d3..b0128607ac5 100644
--- a/document/src/tests/documenttestcase.cpp
+++ b/document/src/tests/documenttestcase.cpp
@@ -28,7 +28,8 @@ using namespace fieldvalue;
TEST(DocumentTest, testSizeOf)
{
- EXPECT_EQ(136ul, sizeof(Document));
+ EXPECT_EQ(24ul, sizeof(DocumentId));
+ EXPECT_EQ(128ul, sizeof(Document));
EXPECT_EQ(72ul, sizeof(StructFieldValue));
EXPECT_EQ(24ul, sizeof(StructuredFieldValue));
EXPECT_EQ(64ul, sizeof(SerializableArray));
diff --git a/document/src/tests/fieldvalue/referencefieldvalue_test.cpp b/document/src/tests/fieldvalue/referencefieldvalue_test.cpp
index 17fb5ac74e6..b42e2d9cd7a 100644
--- a/document/src/tests/fieldvalue/referencefieldvalue_test.cpp
+++ b/document/src/tests/fieldvalue/referencefieldvalue_test.cpp
@@ -122,7 +122,7 @@ TEST_F("clone()ing creates new instance with same ID and type", Fixture) {
ReferenceFieldValue src(f.refType, DocumentId("id:ns:foo::yoshi"));
std::unique_ptr<ReferenceFieldValue> cloned(src.clone());
- ASSERT_TRUE(cloned.get() != nullptr);
+ ASSERT_TRUE(cloned);
ASSERT_TRUE(cloned->hasValidDocumentId());
EXPECT_EQUAL(src.getDocumentId(), cloned->getDocumentId());
EXPECT_EQUAL(src.getDataType(), cloned->getDataType());
@@ -133,7 +133,7 @@ TEST_F("Can clone() value without document ID", Fixture) {
ReferenceFieldValue src(f.refType);
std::unique_ptr<ReferenceFieldValue> cloned(src.clone());
- ASSERT_TRUE(cloned.get() != nullptr);
+ ASSERT_TRUE(cloned);
EXPECT_FALSE(cloned->hasValidDocumentId());
EXPECT_EQUAL(src.getDataType(), cloned->getDataType());
EXPECT_TRUE(cloned->hasChanged());
diff --git a/document/src/vespa/document/base/documentid.cpp b/document/src/vespa/document/base/documentid.cpp
index c3ba8fea29d..5c240922e6d 100644
--- a/document/src/vespa/document/base/documentid.cpp
+++ b/document/src/vespa/document/base/documentid.cpp
@@ -9,68 +9,45 @@ using vespalib::nbostream;
namespace document {
DocumentId::DocumentId()
- : Printable(),
- _globalId(),
+ : _globalId(),
_id(new NullIdString())
{
}
DocumentId::DocumentId(vespalib::stringref id)
- : Printable(),
- _globalId(),
+ : _globalId(),
_id(IdString::createIdString(id.data(), id.size()).release())
{
}
DocumentId::DocumentId(vespalib::nbostream & is)
- : Printable(),
- _globalId(),
+ : _globalId(),
_id(IdString::createIdString(is.peek(), strlen(is.peek())).release())
{
is.adjustReadPos(strlen(is.peek()) + 1);
}
-DocumentId::DocumentId(const IdString& id)
- : Printable(),
- _globalId(),
- _id(id.clone())
-{
-}
+DocumentId::DocumentId(const DocumentId & rhs) = default;
+DocumentId & DocumentId::operator = (const DocumentId & rhs) = default;
+DocumentId::~DocumentId() = default;
vespalib::string
DocumentId::toString() const {
return _id->toString();
}
-void DocumentId::set(vespalib::stringref id) {
+void
+DocumentId::set(vespalib::stringref id) {
_id.reset(IdString::createIdString(id).release());
_globalId.first = false;
}
-void
-DocumentId::print(std::ostream& out, bool verbose, const std::string& indent) const
-{
- (void) indent;
- if (verbose) {
- out << "DocumentId(id = ";
- }
- out << _id->toString().c_str();
- if (verbose) {
- out << ", " << getGlobalId().toString() << ")";
- }
-}
-
size_t
DocumentId::getSerializedSize() const
{
return _id->toString().size() + 1;
}
-void DocumentId::swap(DocumentId & rhs) {
- _id.swap(rhs._id);
- std::swap(_globalId, rhs._globalId);
-}
-
void
DocumentId::calculateGlobalId() const
{
@@ -86,5 +63,9 @@ DocumentId::calculateGlobalId() const
_globalId.second.set(key);
}
+std::ostream &
+operator << (std::ostream & os, const DocumentId & id) {
+ return os << id.toString();
+}
} // document
diff --git a/document/src/vespa/document/base/documentid.h b/document/src/vespa/document/base/documentid.h
index a4b01cdad82..99ab63bd296 100644
--- a/document/src/vespa/document/base/documentid.h
+++ b/document/src/vespa/document/base/documentid.h
@@ -21,7 +21,6 @@
#include "idstring.h"
#include "globalid.h"
-#include <vespa/document/util/printable.h>
namespace vespalib { class nbostream; }
@@ -29,14 +28,18 @@ namespace document {
class DocumentType;
-class DocumentId : public Printable
+class DocumentId
{
public:
typedef std::unique_ptr<DocumentId> UP;
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();
/**
* Parse the given document identifier given as string, and create an
* identifier object from it.
@@ -57,8 +60,6 @@ public:
*/
vespalib::string toString() const;
- void print(std::ostream& out, bool verbose, const std::string& indent) const override;
-
bool operator==(const DocumentId& other) const { return *_id == *other._id; }
bool operator!=(const DocumentId& other) const { return ! (*_id == *other._id); }
@@ -71,9 +72,7 @@ public:
return _globalId.second;
}
- DocumentId* clone() const { return new DocumentId(*this); }
- virtual size_t getSerializedSize() const;
- void swap(DocumentId & rhs);
+ size_t getSerializedSize() const;
private:
mutable std::pair<bool, GlobalId> _globalId;
vespalib::CloneablePtr<IdString> _id;
@@ -81,5 +80,7 @@ private:
void calculateGlobalId() const;
};
+std::ostream & operator << (std::ostream & os, const DocumentId & id);
+
} // document
diff --git a/document/src/vespa/document/base/idstring.cpp b/document/src/vespa/document/base/idstring.cpp
index 05dc52475b7..1dcc11aa891 100644
--- a/document/src/vespa/document/base/idstring.cpp
+++ b/document/src/vespa/document/base/idstring.cpp
@@ -5,7 +5,6 @@
#include <vespa/document/bucket/bucketid.h>
#include <vespa/vespalib/util/md5.h>
#include <vespa/vespalib/util/stringfmt.h>
-#include <limits>
#include <cerrno>
using vespalib::string;
@@ -31,12 +30,6 @@ IdString::getTypeName(Type t)
return _G_typeName[t];
}
-string
-IdString::getSchemeName() const
-{
- return getTypeName(getType());
-}
-
const string &
IdString::toString() const
{
@@ -74,11 +67,6 @@ union FourByte {
uint32_t as32;
};
-union EightByte {
- char asChar[8];
- uint64_t as64;
-};
-
const FourByte _G_null = {{'n', 'u', 'l', 'l'}};
const TwoByte _G_id = {{'i', 'd'}};
@@ -128,7 +116,7 @@ fmemchr(const char * s, const char * e)
}
s++;
}
- return NULL;
+ return nullptr;
}
} // namespace
@@ -141,7 +129,7 @@ IdString::Offsets::Offsets(uint32_t maxComponents, uint32_t namespaceOffset, str
const char * s(id.data() + namespaceOffset);
const char * e(id.data() + id.size());
for(s=fmemchr(s, e);
- (s != NULL) && (index < maxComponents);
+ (s != nullptr) && (index < maxComponents);
s = fmemchr(s+1, e))
{
_offsets[index++] = s - id.data() + 1;
@@ -159,6 +147,8 @@ IdString::IdString(uint32_t maxComponents, uint32_t namespaceOffset, stringref r
{
}
+IdString::~IdString() = default;
+
void
IdString::validate() const
{
@@ -205,7 +195,7 @@ union LocationUnion {
};
uint64_t parseNumber(stringref number) {
- char* errPos = NULL;
+ char* errPos = nullptr;
errno = 0;
uint64_t n = strtoul(number.data(), &errPos, 10);
if (*errPos) {
diff --git a/document/src/vespa/document/base/idstring.h b/document/src/vespa/document/base/idstring.h
index cddf6d036b1..8e8cf0057dc 100644
--- a/document/src/vespa/document/base/idstring.h
+++ b/document/src/vespa/document/base/idstring.h
@@ -28,7 +28,7 @@ public:
static IdString::UP createIdString(const char *id, size_t sz);
static LocationType makeLocation(vespalib::stringref s);
- ~IdString() {}
+ ~IdString();
IdString* clone() const override = 0;
virtual Type getType() const = 0;
@@ -50,7 +50,6 @@ public:
protected:
IdString(uint32_t maxComponents, uint32_t namespaceOffset, vespalib::stringref rawId);
- virtual vespalib::string getSchemeName() const;
size_t offset(size_t index) const { return _offsets[index]; }
size_t size(size_t index) const { return _offsets[index+1] - _offsets[index] - 1; }
vespalib::stringref getComponent(size_t index) const { return vespalib::stringref(_rawId.c_str() + offset(index), size(index)); }
diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp
index 1bcee490378..29414c901f8 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>
@@ -43,7 +42,10 @@ void throwTypeMismatch(vespalib::stringref type, vespalib::stringref docidType)
VESPA_STRLOC);
}
-const DataType &verifyDocumentType(const DataType *type) {
+} // namespace
+
+const DataType &
+Document::verifyDocumentType(const DataType *type) {
if (!type) {
documentTypeError("null");
} else if ( ! type->getClass().inherits(DocumentType::classId)) {
@@ -51,7 +53,20 @@ const DataType &verifyDocumentType(const DataType *type) {
}
return *type;
}
-} // namespace
+
+void
+Document::verifyIdAndType(const DocumentId & id, const DataType *type) {
+ verifyDocumentType(type);
+ if (id.hasDocType() && (id.getDocType() != type->getName())) {
+ throwTypeMismatch(type->getName(), id.getDocType());
+ }
+}
+
+void
+Document::setType(const DataType & type) {
+ StructuredFieldValue::setType(type);
+ _fields.setType(getType().getFieldsType());
+}
IMPLEMENT_IDENTIFIABLE_ABSTRACT(Document, StructuredFieldValue);
@@ -64,38 +79,18 @@ Document::Document()
_fields.setDocumentType(getType());
}
-Document::Document(const Document& other)
- : StructuredFieldValue(other),
- _id(other._id),
- _fields(other._fields),
- _lastModified(other._lastModified)
-{
-}
-
-Document::Document(const DataType &type, const DocumentId& documentId)
- : StructuredFieldValue(verifyDocumentType(&type)),
- _id(documentId),
- _fields(getType().getFieldsType()),
- _lastModified(0)
-{
- _fields.setDocumentType(getType());
- if (documentId.hasDocType() && documentId.getDocType() != type.getName()) {
- throwTypeMismatch(type.getName(), documentId.getDocType());
- }
-}
+Document::Document(const Document& other) = default;
-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,31 +143,14 @@ Document::Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer&
deserializeBody(repo, body);
}
-Document::~Document() {
-}
-
-void
-Document::swap(Document & rhs)
-{
- StructuredFieldValue::swap(rhs);
- _fields.swap(rhs._fields);
- _id.swap(rhs._id);
- std::swap(_lastModified, rhs._lastModified);
-}
+Document::~Document() = default;
const DocumentType&
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 +188,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 +199,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 +212,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 +287,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..3e1ec0da3e6 100644
--- a/document/src/vespa/document/fieldvalue/document.h
+++ b/document/src/vespa/document/fieldvalue/document.h
@@ -36,30 +36,30 @@ public:
typedef std::shared_ptr<Document> SP;
static constexpr uint16_t getNewestSerializationVersion() { return 8; }
+ static const DataType & verifyDocumentType(const DataType *type);
+ static void verifyIdAndType(const DocumentId & id, const DataType *type);
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 id);
+ 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(); }
Document& operator=(const Document&);
- void swap(Document & rhs);
-
void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); }
void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); }
+ void setType(const DataType & type) override;
const DocumentType& getType() const;
const DocumentId& getId() const { return _id; }
DocumentId & getId() { return _id; }
@@ -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/fieldvalue/fieldvalue.h b/document/src/vespa/document/fieldvalue/fieldvalue.h
index bfdc907e871..a152f74cc09 100644
--- a/document/src/vespa/document/fieldvalue/fieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/fieldvalue.h
@@ -47,7 +47,7 @@ public:
DECLARE_IDENTIFIABLE_ABSTRACT(FieldValue);
- FieldValue() {}
+ FieldValue() = default;
/**
* Visit this fieldvalue for double dispatch.
diff --git a/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp b/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp
index 281161fccbf..6c046c1787b 100644
--- a/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp
@@ -37,8 +37,7 @@ ReferenceFieldValue::ReferenceFieldValue(
requireIdOfMatchingType(_documentId, _dataType->getTargetType());
}
-ReferenceFieldValue::~ReferenceFieldValue() {
-}
+ReferenceFieldValue::~ReferenceFieldValue() = default;
void ReferenceFieldValue::requireIdOfMatchingType(
const DocumentId& id, const DocumentType& type)
@@ -105,9 +104,7 @@ int ReferenceFieldValue::compare(const FieldValue& rhs) const {
void ReferenceFieldValue::print(std::ostream& os, bool verbose, const std::string& indent) const {
(void) verbose;
assert(_dataType != nullptr);
- os << indent << "ReferenceFieldValue(" << *_dataType << ", DocumentId(";
- _documentId.print(os, false, "");
- os << "))";
+ os << indent << "ReferenceFieldValue(" << *_dataType << ", DocumentId(" << _documentId << "))";
}
bool ReferenceFieldValue::hasChanged() const {
diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
index 80b86997122..87c8d09648c 100644
--- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
@@ -32,16 +32,19 @@ IMPLEMENT_IDENTIFIABLE_ABSTRACT(StructFieldValue, StructuredFieldValue);
StructFieldValue::StructFieldValue(const DataType &type)
: StructuredFieldValue(type),
- _repo(NULL),
- _doc_type(NULL),
+ _repo(nullptr),
+ _doc_type(nullptr),
_version(Document::getNewestSerializationVersion()),
_hasChanged(true)
{
}
-StructFieldValue::~StructFieldValue() { }
+StructFieldValue::StructFieldValue(const StructFieldValue & rhs) = default;
+StructFieldValue & StructFieldValue::operator = (const StructFieldValue & rhs) = default;
-StructFieldValue::Chunks::~Chunks() { }
+StructFieldValue::~StructFieldValue() = default;
+
+StructFieldValue::Chunks::~Chunks() = default;
void
StructFieldValue::Chunks::push_back(SerializableArray::UP item) {
@@ -56,24 +59,6 @@ StructFieldValue::Chunks::clear() {
_sz = 0;
}
-void
-StructFieldValue::Chunks::swap(Chunks & rhs) {
- _chunks[0].swap(rhs._chunks[0]);
- _chunks[1].swap(rhs._chunks[1]);
- std::swap(_sz, rhs._sz);
-}
-
-void
-StructFieldValue::swap(StructFieldValue & rhs)
-{
- StructuredFieldValue::swap(rhs);
- std::swap(_chunks, rhs._chunks);
- std::swap(_hasChanged, rhs._hasChanged);
- std::swap(_repo, rhs._repo);
- std::swap(_doc_type, rhs._doc_type);
- std::swap(_version, _version);
-}
-
const StructDataType &
StructFieldValue::getStructType() const {
return static_cast<const StructDataType &>(getType());
diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h
index 0a288aeb69d..b5b15e9dfce 100644
--- a/document/src/vespa/document/fieldvalue/structfieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h
@@ -37,7 +37,6 @@ public:
size_t size() const { return _sz; }
bool empty() const { return _sz == 0; }
VESPA_DLL_LOCAL void clear();
- VESPA_DLL_LOCAL void swap(Chunks & rhs);
private:
SerializableArray::CP _chunks[2];
size_t _sz;
@@ -56,8 +55,9 @@ public:
using CompressionConfig = vespalib::compression::CompressionConfig;
StructFieldValue(const DataType &type);
- ~StructFieldValue();
- void swap(StructFieldValue & rhs);
+ StructFieldValue(const StructFieldValue & rhs);
+ StructFieldValue & operator = (const StructFieldValue & rhs);
+ ~StructFieldValue() override;
void setRepo(const DocumentTypeRepo & repo) { _repo = & repo; }
const DocumentTypeRepo * getRepo() const { return _repo; }
diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp
index 860151e4bb4..39af319bc8a 100644
--- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp
@@ -41,12 +41,8 @@ StructuredFieldValue::StructuredFieldValue(const DataType &type)
{
}
-StructuredFieldValue::~StructuredFieldValue() {}
+StructuredFieldValue::~StructuredFieldValue() = default;
-void StructuredFieldValue::setType(const DataType& type)
-{
- _type = &type;
-}
StructuredFieldValue&
StructuredFieldValue::operator=(const StructuredFieldValue& other)
@@ -61,7 +57,8 @@ StructuredFieldValue::operator=(const StructuredFieldValue& other)
return *this;
}
-void StructuredFieldValue::setFieldValue(const Field & field, const FieldValue & value)
+void
+StructuredFieldValue::setFieldValue(const Field & field, const FieldValue & value)
{
if (!field.getDataType().isValueType(value) &&
!value.getDataType()->isA(field.getDataType()))
diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h
index 619c8cf7f06..b81dc8e3936 100644
--- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h
@@ -44,13 +44,13 @@ class StructuredFieldValue : public FieldValue
VESPA_DLL_LOCAL void returnValue(const Field & field, FieldValue::UP value) const;
protected:
- StructuredFieldValue(const DataType &type);
+ VESPA_DLL_LOCAL StructuredFieldValue(const DataType &type);
StructuredFieldValue(const StructuredFieldValue&);
StructuredFieldValue& operator=(const StructuredFieldValue&);
- void swap(StructuredFieldValue & rhs) { std::swap(_type, rhs._type); }
+ ~StructuredFieldValue() override;
/** Called from Document when deserializing alters type. */
- virtual void setType(const DataType& type);
+ virtual void setType(const DataType& type) { _type = &type; }
const DataType &getType() const { return *_type; }
struct StructuredIterator {
@@ -77,10 +77,10 @@ protected:
}
bool operator==(const Iterator& other) const {
- if (_field == 0 && other._field == 0)
+ if (_field == nullptr && other._field == nullptr)
// both at end()
return true;
- if (_field == 0 || other._field == 0)
+ if (_field == nullptr || other._field == nullptr)
// one at end()
return false;
return (*_field == *other._field);
@@ -105,9 +105,8 @@ protected:
onIterateNested(PathRange nested, fieldvalue::IteratorHandler & handler) const override;
public:
DECLARE_IDENTIFIABLE_ABSTRACT(StructuredFieldValue);
- ~StructuredFieldValue();
- virtual StructuredFieldValue* clone() const override = 0;
+ StructuredFieldValue* clone() const override = 0;
const DataType *getDataType() const override { return _type; }
/** Wrapper for DataType's hasField() function. */
diff --git a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp
index a0eaa9d8154..4fe7cfc6d29 100644
--- a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp
+++ b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp
@@ -72,8 +72,10 @@ 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);
- value.swap(newDoc);
+ Document::verifyIdAndType(value.getId(), type);
+ value.setType(*type);
+ value.clear();
+ value.setLastModified(0);
}
value.setRepo(_repo.getDocumentTypeRepo());