aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-14 13:50:09 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-01-14 13:50:54 +0000
commita772cb05a682fd05fabd0d571417ec7976d0165d (patch)
tree7b81ef07e84c8f1e9c14934ccaa2ab85645eb2d5 /document
parent6ddc242f9ab1331c9bf0d5ce373a7a4e3b153196 (diff)
Avoid swap. Inline and use anonymous namespaces for better code generation.
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/fieldvalue/document.cpp29
-rw-r--r--document/src/vespa/document/fieldvalue/document.h5
-rw-r--r--document/src/vespa/document/fieldvalue/fieldvalue.h2
-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
8 files changed, 45 insertions, 54 deletions
diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp
index 110bbeca6cd..29414c901f8 100644
--- a/document/src/vespa/document/fieldvalue/document.cpp
+++ b/document/src/vespa/document/fieldvalue/document.cpp
@@ -42,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)) {
@@ -50,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);
@@ -129,15 +145,6 @@ Document::Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer&
Document::~Document() = default;
-void
-Document::swap(Document & rhs)
-{
- StructuredFieldValue::swap(rhs);
- _fields.swap(rhs._fields);
- _id.swap(rhs._id);
- std::swap(_lastModified, rhs._lastModified);
-}
-
const DocumentType&
Document::getType() const {
return static_cast<const DocumentType &>(StructuredFieldValue::getType());
diff --git a/document/src/vespa/document/fieldvalue/document.h b/document/src/vespa/document/fieldvalue/document.h
index d69f202c460..3e1ec0da3e6 100644
--- a/document/src/vespa/document/fieldvalue/document.h
+++ b/document/src/vespa/document/fieldvalue/document.h
@@ -36,6 +36,8 @@ 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&);
@@ -54,11 +56,10 @@ public:
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; }
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/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 5770de5f392..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, std::move(value.getId()));
- value.swap(newDoc);
+ Document::verifyIdAndType(value.getId(), type);
+ value.setType(*type);
+ value.clear();
+ value.setLastModified(0);
}
value.setRepo(_repo.getDocumentTypeRepo());