summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-05-29 20:34:37 +0200
committerHenning Baldersheim <balder@oath.com>2018-05-29 21:16:22 +0200
commita364dea87f200335cf1e68d61b87820eda4019b7 (patch)
tree7d4043e424e26cf2ae95fcf079fc8d0ea4137ed3 /document
parent3692687d3474946da3d36dd86cad753ed0ac229a (diff)
Avoid copy construction by creating in place upon construction.
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/update/fieldupdate.cpp29
-rw-r--r--document/src/vespa/document/update/fieldupdate.h8
2 files changed, 26 insertions, 11 deletions
diff --git a/document/src/vespa/document/update/fieldupdate.cpp b/document/src/vespa/document/update/fieldupdate.cpp
index 667b9198c11..7cf01576869 100644
--- a/document/src/vespa/document/update/fieldupdate.cpp
+++ b/document/src/vespa/document/update/fieldupdate.cpp
@@ -16,6 +16,28 @@ FieldUpdate::FieldUpdate(const Field& field)
{
}
+namespace {
+
+ int readInt(ByteBuffer & buffer) {
+ int fieldId;
+ buffer.getIntNetwork(fieldId);
+ return fieldId;
+ }
+}
+
+FieldUpdate::FieldUpdate(const DocumentTypeRepo& repo, const DocumentType& type, ByteBuffer& buffer, int16_t version)
+ : Printable(),
+ _field(type.getField(readInt(buffer))),
+ _updates()
+{
+ int numUpdates = readInt(buffer);
+ _updates.reserve(numUpdates);
+ const DataType& dataType = _field.getDataType();
+ for(int i(0); i < numUpdates; i++) {
+ _updates.emplace_back(ValueUpdate::createInstance(repo, dataType, buffer, version).release());
+ }
+}
+
FieldUpdate::FieldUpdate(const FieldUpdate &) = default;
FieldUpdate & FieldUpdate::operator = (const FieldUpdate &) = default;
FieldUpdate::~FieldUpdate() = default;
@@ -65,8 +87,7 @@ FieldUpdate::applyTo(Document& doc) const
// Print this field update as a human readable string.
void
-FieldUpdate::print(std::ostream& out, bool verbose,
- const std::string& indent) const
+FieldUpdate::print(std::ostream& out, bool verbose, const std::string& indent) const
{
out << "FieldUpdate(" << _field.toString(verbose);
for(const auto & update : _updates) {
@@ -81,8 +102,8 @@ FieldUpdate::print(std::ostream& out, bool verbose,
// Deserialize this field update from the given buffer.
void
-FieldUpdate::deserialize(const DocumentTypeRepo& repo,
- const DocumentType& docType, ByteBuffer& buffer, int16_t version)
+FieldUpdate::deserialize(const DocumentTypeRepo& repo, const DocumentType& docType,
+ ByteBuffer& buffer, int16_t version)
{
int fieldId;
buffer.getIntNetwork(fieldId);
diff --git a/document/src/vespa/document/update/fieldupdate.h b/document/src/vespa/document/update/fieldupdate.h
index 9c2ba66a56d..569fb21fe1c 100644
--- a/document/src/vespa/document/update/fieldupdate.h
+++ b/document/src/vespa/document/update/fieldupdate.h
@@ -49,13 +49,7 @@ public:
* @param serializationVersion The serialization version the update was serialized with.
*/
FieldUpdate(const DocumentTypeRepo& repo, const DocumentType& type,
- ByteBuffer& buffer, int16_t version)
- : Printable(),
- _field(),
- _updates()
- {
- deserialize(repo, type, buffer, version);
- }
+ ByteBuffer& buffer, int16_t version);
bool operator==(const FieldUpdate&) const;
bool operator!=(const FieldUpdate & rhs) const { return ! (*this == rhs); }