From 3112b96dcd66e8aed0587d44288ca8e347cc31a2 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Sun, 27 Mar 2022 14:05:51 +0000 Subject: Avoid need to copy/clone FieldUpdate --- document/src/tests/documentselectparsertest.cpp | 10 +- document/src/tests/documentupdatetestcase.cpp | 148 ++++++++++----------- document/src/tests/testxml.cpp | 26 ++-- .../src/vespa/document/update/documentupdate.cpp | 4 +- .../src/vespa/document/update/documentupdate.h | 2 +- document/src/vespa/document/update/fieldupdate.cpp | 11 +- document/src/vespa/document/update/fieldupdate.h | 25 ++-- .../conformancetest/conformancetest.cpp | 65 +++------ .../src/tests/proton/attribute/attribute_test.cpp | 18 +-- .../documentdb/feedhandler/feedhandler_test.cpp | 10 +- .../proton/feedoperation/feedoperation_test.cpp | 5 +- .../persistenceengine/persistenceengine_test.cpp | 38 +++--- .../src/vespa/searchcore/bmcluster/bm_feed.cpp | 5 +- .../distributor/externaloperationhandlertest.cpp | 3 +- .../distributor/twophaseupdateoperationtest.cpp | 4 +- .../src/tests/persistence/persistencetestutils.cpp | 8 +- storage/src/tests/persistence/testandsettest.cpp | 5 +- .../src/tests/mbusprot/storageprotocoltest.cpp | 4 +- 18 files changed, 170 insertions(+), 221 deletions(-) diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index 5c263daaa31..443686dde19 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -137,11 +137,11 @@ DocumentUpdate::SP DocumentSelectParserTest::createUpdate( const std::string& hstr) { const DocumentType* type = _repo->getDocumentType(doctype); - DocumentUpdate::SP doc(new DocumentUpdate(*_repo, *type, DocumentId(id))); - doc->addUpdate(FieldUpdate(doc->getType().getField("headerval")) - .addUpdate(AssignValueUpdate(IntFieldValue(hint)))); - doc->addUpdate(FieldUpdate(doc->getType().getField("hstringval")) - .addUpdate(AssignValueUpdate(StringFieldValue(hstr)))); + auto doc = std::make_shared(*_repo, *type, DocumentId(id)); + doc->addUpdate(std::move(FieldUpdate(doc->getType().getField("headerval")) + .addUpdate(AssignValueUpdate(IntFieldValue(hint))))); + doc->addUpdate(std::move(FieldUpdate(doc->getType().getField("hstringval")) + .addUpdate(AssignValueUpdate(StringFieldValue(hstr))))); return doc; } diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index e1e86bca671..a1b5bb17df9 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -133,7 +133,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) // Test that a document update can be serialized DocumentUpdate docUpdate(repo, *docType, DocumentId("id:ns:test::1")); - docUpdate.addUpdate(fieldUpdateCopy); + docUpdate.addUpdate(std::move(fieldUpdateCopy)); nbostream docBuf = serializeHEAD(docUpdate); auto docUpdateCopy(DocumentUpdate::createHEAD(repo, docBuf)); @@ -150,7 +150,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(FieldUpdate(docType->getField("intf")).addUpdate(ClearValueUpdate())); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(ClearValueUpdate()))); upd.applyTo(updated); EXPECT_NE(doc, updated); EXPECT_FALSE(updated.getValue("intf")); @@ -158,7 +158,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(FieldUpdate(docType->getField("intf")).addUpdate(AssignValueUpdate(IntFieldValue(15)))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(AssignValueUpdate(IntFieldValue(15))))); upd.applyTo(updated); EXPECT_NE(doc, updated); EXPECT_EQ(15, updated.getValue("intf")->getAsInt()); @@ -166,7 +166,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(FieldUpdate(docType->getField("intf")).addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 15))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 15)))); upd.applyTo(updated); EXPECT_NE(doc, updated); EXPECT_EQ(20, updated.getValue("intf")->getAsInt()); @@ -174,7 +174,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(FieldUpdate(docType->getField("intarr")).addUpdate(AddValueUpdate(IntFieldValue(4)))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intarr")).addUpdate(AddValueUpdate(IntFieldValue(4))))); upd.applyTo(updated); EXPECT_NE(doc, updated); std::unique_ptr val(dynamic_cast(updated.getValue("intarr").release())); @@ -184,7 +184,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(FieldUpdate(docType->getField("intarr")).addUpdate(RemoveValueUpdate(IntFieldValue(3)))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intarr")).addUpdate(RemoveValueUpdate(IntFieldValue(3))))); upd.applyTo(updated); EXPECT_NE(doc, updated); std::unique_ptr val(dynamic_cast(updated.getValue("intarr").release())); @@ -194,8 +194,8 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(FieldUpdate(docType->getField("bytef")) - .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 15))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("bytef")) + .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 15)))); upd.applyTo(updated); EXPECT_NE(doc, updated); EXPECT_EQ(15, (int) updated.getValue("bytef")->getAsByte()); @@ -212,7 +212,7 @@ TEST(DocumentUpdateTest, testClearField) // Apply an update. DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(doc->getField("headerval")).addUpdate(AssignValueUpdate())) + .addUpdate(std::move(FieldUpdate(doc->getField("headerval")).addUpdate(AssignValueUpdate()))) .applyTo(*doc); EXPECT_FALSE(doc->getValue("headerval")); } @@ -227,7 +227,7 @@ TEST(DocumentUpdateTest, testUpdateApplySingleValue) // Apply an update. DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(doc->getField("headerval")).addUpdate(AssignValueUpdate(IntFieldValue(9)))) + .addUpdate(std::move(FieldUpdate(doc->getField("headerval")).addUpdate(AssignValueUpdate(IntFieldValue(9))))) .applyTo(*doc); EXPECT_EQ(9, doc->getValue("headerval")->getAsInt()); } @@ -245,7 +245,7 @@ TEST(DocumentUpdateTest, testUpdateArray) myarray.add(StringFieldValue("bar")); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(doc->getField("tags")).addUpdate(AssignValueUpdate(myarray))) + .addUpdate(std::move(FieldUpdate(doc->getField("tags")).addUpdate(AssignValueUpdate(myarray)))) .applyTo(*doc); auto fval1(doc->getAs(doc->getField("tags"))); ASSERT_EQ((size_t) 2, fval1->size()); @@ -254,9 +254,9 @@ TEST(DocumentUpdateTest, testUpdateArray) // Append array field DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(doc->getField("tags")) + .addUpdate(std::move(FieldUpdate(doc->getField("tags")) .addUpdate(AddValueUpdate(StringFieldValue("another"))) - .addUpdate(AddValueUpdate(StringFieldValue("tag")))) + .addUpdate(AddValueUpdate(StringFieldValue("tag"))))) .applyTo(*doc); std::unique_ptr fval2(doc->getAs(doc->getField("tags"))); @@ -269,16 +269,16 @@ TEST(DocumentUpdateTest, testUpdateArray) // Append single value. ASSERT_THROW( DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(doc->getField("tags")) - .addUpdate(AssignValueUpdate(StringFieldValue("THROW MEH!")))) + .addUpdate(std::move(FieldUpdate(doc->getField("tags")) + .addUpdate(AssignValueUpdate(StringFieldValue("THROW MEH!"))))) .applyTo(*doc), std::exception) << "Expected exception when assigning a string value to an array field."; // Remove array field. DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(doc->getField("tags")) + .addUpdate(std::move(FieldUpdate(doc->getField("tags")) .addUpdate(RemoveValueUpdate(StringFieldValue("foo"))) - .addUpdate(RemoveValueUpdate(StringFieldValue("tag")))) + .addUpdate(RemoveValueUpdate(StringFieldValue("tag"))))) .applyTo(*doc); auto fval3(doc->getAs(doc->getField("tags"))); ASSERT_EQ((size_t) 2, fval3->size()); @@ -291,8 +291,8 @@ TEST(DocumentUpdateTest, testUpdateArray) myarray2.add(StringFieldValue("bar")); ASSERT_THROW( DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(doc->getField("tags")) - .addUpdate(RemoveValueUpdate(myarray2))) + .addUpdate(std::move(FieldUpdate(doc->getField("tags")) + .addUpdate(RemoveValueUpdate(myarray2)))) .applyTo(*doc), std::exception) << "Expected exception when removing an array from a string array."; } @@ -310,7 +310,7 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) wset.add(StringFieldValue("foo"), 3); wset.add(StringFieldValue("bar"), 14); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field).addUpdate(AssignValueUpdate(wset))) + .addUpdate(std::move(FieldUpdate(field).addUpdate(AssignValueUpdate(wset)))) .applyTo(*doc); auto fval1(doc->getAs(field)); ASSERT_EQ((size_t) 2, fval1->size()); @@ -326,8 +326,8 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) wset2.add(StringFieldValue("foo"), 16); wset2.add(StringFieldValue("bar"), 24); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field) - .addUpdate(AssignValueUpdate(wset2))) + .addUpdate(std::move(FieldUpdate(field) + .addUpdate(AssignValueUpdate(wset2)))) .applyTo(*doc); auto fval2(doc->getAs(field)); ASSERT_EQ((size_t) 2, fval2->size()); @@ -340,9 +340,9 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) // Append weighted field DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field) + .addUpdate(std::move(FieldUpdate(field) .addUpdate(AddValueUpdate(StringFieldValue("foo")).setWeight(3)) - .addUpdate(AddValueUpdate(StringFieldValue("too")).setWeight(14))) + .addUpdate(AddValueUpdate(StringFieldValue("too")).setWeight(14)))) .applyTo(*doc); std::unique_ptr fval3(doc->getAs(field)); @@ -356,9 +356,9 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) // Remove weighted field DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field) + .addUpdate(std::move(FieldUpdate(field) .addUpdate(RemoveValueUpdate(StringFieldValue("foo"))) - .addUpdate(RemoveValueUpdate(StringFieldValue("too")))) + .addUpdate(RemoveValueUpdate(StringFieldValue("too"))))) .applyTo(*doc); auto fval4(doc->getAs(field)); ASSERT_EQ((size_t) 1, fval4->size()); @@ -404,9 +404,9 @@ WeightedSetAutoCreateFixture::WeightedSetAutoCreateFixture() field(docType->getField("strwset")), update(repo, *docType, DocumentId("id:ns:test::1")) { - update.addUpdate(FieldUpdate(field) + update.addUpdate(std::move(FieldUpdate(field) .addUpdate(MapValueUpdate(StringFieldValue("foo"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1)))); + ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1))))); } } // anon ns @@ -442,9 +442,9 @@ TEST(DocumentUpdateTest, testIncrementExistingWSetField) TEST(DocumentUpdateTest, testIncrementWithZeroResultWeightIsRemoved) { WeightedSetAutoCreateFixture fixture; - fixture.update.addUpdate(FieldUpdate(fixture.field) + fixture.update.addUpdate(std::move(FieldUpdate(fixture.field) .addUpdate(MapValueUpdate(StringFieldValue("baz"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 0)))); + ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 0))))); fixture.applyUpdateToDocument(); @@ -524,21 +524,21 @@ TEST(DocumentUpdateTest, testGenerateSerializedFile) const DocumentType *type(repo.getDocumentType("serializetest")); DocumentUpdate upd(repo, *type, DocumentId("id:ns:serializetest::update")); - upd.addUpdate(FieldUpdate(type->getField("intfield")) - .addUpdate(AssignValueUpdate(IntFieldValue(4)))); - upd.addUpdate(FieldUpdate(type->getField("floatfield")) - .addUpdate(AssignValueUpdate(FloatFieldValue(1.00f)))); - upd.addUpdate(FieldUpdate(type->getField("arrayoffloatfield")) + upd.addUpdate(std::move(FieldUpdate(type->getField("intfield")) + .addUpdate(AssignValueUpdate(IntFieldValue(4))))); + upd.addUpdate(std::move(FieldUpdate(type->getField("floatfield")) + .addUpdate(AssignValueUpdate(FloatFieldValue(1.00f))))); + upd.addUpdate(std::move(FieldUpdate(type->getField("arrayoffloatfield")) .addUpdate(AddValueUpdate(FloatFieldValue(5.00f))) .addUpdate(AddValueUpdate(FloatFieldValue(4.23f))) - .addUpdate(AddValueUpdate(FloatFieldValue(-1.00f)))); - upd.addUpdate(FieldUpdate(type->getField("intfield")) - .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 3))); - upd.addUpdate(FieldUpdate(type->getField("wsfield")) + .addUpdate(AddValueUpdate(FloatFieldValue(-1.00f))))); + upd.addUpdate(std::move(FieldUpdate(type->getField("intfield")) + .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 3)))); + upd.addUpdate(std::move(FieldUpdate(type->getField("wsfield")) .addUpdate(MapValueUpdate(StringFieldValue("foo"), ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 2))) .addUpdate(MapValueUpdate(StringFieldValue("foo"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Mul, 2)))); + ArithmeticValueUpdate(ArithmeticValueUpdate::Mul, 2))))); nbostream buf(serializeHEAD(upd)); writeBufferToFile(buf, "data/serializeupdatecpp.dat"); } @@ -554,8 +554,8 @@ TEST(DocumentUpdateTest, testSetBadFieldTypes) // Assign a float value to an int field. DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); ASSERT_THROW( - update.addUpdate(FieldUpdate(doc->getField("headerval")) - .addUpdate(AssignValueUpdate(FloatFieldValue(4.00f)))), + update.addUpdate(std::move(FieldUpdate(doc->getField("headerval")) + .addUpdate(AssignValueUpdate(FloatFieldValue(4.00f))))), std::exception) << "Expected exception when adding a float to an int field."; update.applyTo(*doc); @@ -572,7 +572,7 @@ TEST(DocumentUpdateTest, testUpdateApplyNoParams) EXPECT_EQ((document::FieldValue*)nullptr, doc->getValue(doc->getField("tags")).get()); DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update.addUpdate(FieldUpdate(doc->getField("tags")).addUpdate(AssignValueUpdate())); + update.addUpdate(std::move(FieldUpdate(doc->getField("tags")).addUpdate(AssignValueUpdate()))); update.applyTo(*doc); @@ -589,8 +589,8 @@ TEST(DocumentUpdateTest, testUpdateApplyNoArrayValues) // Assign array field with no array values = empty array DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update.addUpdate(FieldUpdate(field) - .addUpdate(AssignValueUpdate(ArrayFieldValue(field.getDataType())))); + update.addUpdate(std::move(FieldUpdate(field) + .addUpdate(AssignValueUpdate(ArrayFieldValue(field.getDataType()))))); update.applyTo(*doc); @@ -610,7 +610,7 @@ TEST(DocumentUpdateTest, testUpdateArrayEmptyParamValue) // Assign array field with no array values = empty array. DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update.addUpdate(FieldUpdate(field).addUpdate(AssignValueUpdate(ArrayFieldValue(field.getDataType())))); + update.addUpdate(std::move(FieldUpdate(field).addUpdate(AssignValueUpdate(ArrayFieldValue(field.getDataType()))))); update.applyTo(*doc); // Verify that the field was set in the document. @@ -620,7 +620,7 @@ TEST(DocumentUpdateTest, testUpdateArrayEmptyParamValue) // Remove array field. DocumentUpdate update2(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update2.addUpdate(FieldUpdate(field).addUpdate(ClearValueUpdate())); + update2.addUpdate(std::move(FieldUpdate(field).addUpdate(ClearValueUpdate()))); update2.applyTo(*doc); // Verify that the field was cleared in the document. @@ -638,7 +638,7 @@ TEST(DocumentUpdateTest, testUpdateWeightedSetEmptyParamValue) // Assign weighted set with no items = empty set. DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update.addUpdate(FieldUpdate(field).addUpdate(AssignValueUpdate(WeightedSetFieldValue(field.getDataType())))); + update.addUpdate(std::move(FieldUpdate(field).addUpdate(AssignValueUpdate(WeightedSetFieldValue(field.getDataType()))))); update.applyTo(*doc); // Verify that the field was set in the document. @@ -648,7 +648,7 @@ TEST(DocumentUpdateTest, testUpdateWeightedSetEmptyParamValue) // Remove weighted set field. DocumentUpdate update2(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update2.addUpdate(FieldUpdate(field).addUpdate(ClearValueUpdate())); + update2.addUpdate(std::move(FieldUpdate(field).addUpdate(ClearValueUpdate()))); update2.applyTo(*doc); // Verify that the field was cleared in the document. @@ -667,9 +667,9 @@ TEST(DocumentUpdateTest, testUpdateArrayWrongSubtype) // Assign int values to string array. DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); ASSERT_THROW( - update.addUpdate(FieldUpdate(field) + update.addUpdate(std::move(FieldUpdate(field) .addUpdate(AddValueUpdate(IntFieldValue(123))) - .addUpdate(AddValueUpdate(IntFieldValue(456)))), + .addUpdate(AddValueUpdate(IntFieldValue(456))))), std::exception) << "Expected exception when adding wrong type."; // Apply update @@ -691,9 +691,9 @@ TEST(DocumentUpdateTest, testUpdateWeightedSetWrongSubtype) // Assign int values to string array. DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); ASSERT_THROW( - update.addUpdate(FieldUpdate(field) + update.addUpdate(std::move(FieldUpdate(field) .addUpdate(AddValueUpdate(IntFieldValue(123)).setWeight(1000)) - .addUpdate(AddValueUpdate(IntFieldValue(456)).setWeight(2000))), + .addUpdate(AddValueUpdate(IntFieldValue(456)).setWeight(2000)))), std::exception) << "Expected exception when adding wrong type."; // Apply update @@ -717,29 +717,29 @@ TEST(DocumentUpdateTest, testMapValueUpdate) doc->setValue(field2, wsval2); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field1) + .addUpdate(std::move(FieldUpdate(field1) .addUpdate(MapValueUpdate(StringFieldValue("banana"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0)))) + ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0))))) .applyTo(*doc); std::unique_ptr fv1 = doc->getAs(field1); EXPECT_EQ(0, fv1->size()); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field2) + .addUpdate(std::move(FieldUpdate(field2) .addUpdate(MapValueUpdate(StringFieldValue("banana"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0)))) + ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0))))) .applyTo(*doc); auto fv2 = doc->getAs(field2); EXPECT_EQ(1, fv2->size()); EXPECT_EQ(fv1->find(StringFieldValue("apple")), fv1->end()); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field1).addUpdate(ClearValueUpdate())) + .addUpdate(std::move(FieldUpdate(field1).addUpdate(ClearValueUpdate()))) .applyTo(*doc); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field1).addUpdate(AddValueUpdate(StringFieldValue("apple")).setWeight(1))) + .addUpdate(std::move(FieldUpdate(field1).addUpdate(AddValueUpdate(StringFieldValue("apple")).setWeight(1)))) .applyTo(*doc); auto fval3(doc->getAs(field1)); @@ -747,7 +747,7 @@ TEST(DocumentUpdateTest, testMapValueUpdate) EXPECT_EQ(1, fval3->get(StringFieldValue("apple"))); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field2).addUpdate(AddValueUpdate(StringFieldValue("apple")).setWeight(1))) + .addUpdate(std::move(FieldUpdate(field2).addUpdate(AddValueUpdate(StringFieldValue("apple")).setWeight(1)))) .applyTo(*doc); auto fval3b(doc->getAs(field2)); @@ -755,9 +755,9 @@ TEST(DocumentUpdateTest, testMapValueUpdate) EXPECT_EQ(1, fval3b->get(StringFieldValue("apple"))); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field1) + .addUpdate(std::move(FieldUpdate(field1) .addUpdate(MapValueUpdate(StringFieldValue("apple"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0)))) + ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0))))) .applyTo(*doc); auto fv3 = doc->getAs(field1); @@ -765,9 +765,9 @@ TEST(DocumentUpdateTest, testMapValueUpdate) EXPECT_EQ(0, fv3->get(StringFieldValue("apple"))); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(FieldUpdate(field2) + .addUpdate(std::move(FieldUpdate(field2) .addUpdate(MapValueUpdate(StringFieldValue("apple"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0)))) + ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0))))) .applyTo(*doc); auto fv4 = doc->getAs(field2); @@ -853,7 +853,7 @@ struct TensorUpdateFixture { void applyUpdate(const ValueUpdate &update) { DocumentUpdate docUpdate(docMan.getTypeRepo(), *emptyDoc->getDataType(), emptyDoc->getId()); - docUpdate.addUpdate(FieldUpdate(docUpdate.getType().getField(fieldName)).addUpdate(update)); + docUpdate.addUpdate(std::move(FieldUpdate(docUpdate.getType().getField(fieldName)).addUpdate(update))); docUpdate.applyTo(updatedDoc); } @@ -1147,14 +1147,14 @@ struct TensorUpdateSerializeFixture { auto result = std::make_unique (*repo, docType, DocumentId("id:test:test::0")); - result->addUpdate(FieldUpdate(getField("sparse_tensor")) + result->addUpdate(std::move(FieldUpdate(getField("sparse_tensor")) .addUpdate(AssignValueUpdate(*makeTensor())) .addUpdate(TensorAddUpdate(makeTensor())) - .addUpdate(TensorRemoveUpdate(makeTensor()))); - result->addUpdate(FieldUpdate(getField("dense_tensor")) + .addUpdate(TensorRemoveUpdate(makeTensor())))); + result->addUpdate(std::move(FieldUpdate(getField("dense_tensor")) .addUpdate(TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, makeTensor())) .addUpdate(TensorModifyUpdate(TensorModifyUpdate::Operation::ADD, makeTensor())) - .addUpdate(TensorModifyUpdate(TensorModifyUpdate::Operation::MULTIPLY, makeTensor()))); + .addUpdate(TensorModifyUpdate(TensorModifyUpdate::Operation::MULTIPLY, makeTensor())))); return result; } @@ -1233,10 +1233,10 @@ CreateIfNonExistentFixture::~CreateIfNonExistentFixture() = default; CreateIfNonExistentFixture::CreateIfNonExistentFixture() : docMan(), document(docMan.createDocument()), - update(new DocumentUpdate(docMan.getTypeRepo(), *document->getDataType(), document->getId())) + update(std::make_unique(docMan.getTypeRepo(), *document->getDataType(), document->getId())) { - update->addUpdate(FieldUpdate(document->getField("headerval")) - .addUpdate(AssignValueUpdate(IntFieldValue(1)))); + update->addUpdate(std::move(FieldUpdate(document->getField("headerval")) + .addUpdate(AssignValueUpdate(IntFieldValue(1))))); update->setCreateIfNonExistent(true); } @@ -1267,9 +1267,9 @@ ArrayUpdateFixture::ArrayUpdateFixture() array_field(doc->getType().getField("tags")) // of type array { update = std::make_unique(doc_man.getTypeRepo(), *doc->getDataType(), doc->getId()); - update->addUpdate(FieldUpdate(array_field) + update->addUpdate(std::move(FieldUpdate(array_field) .addUpdate(MapValueUpdate(IntFieldValue(1), - AssignValueUpdate(StringFieldValue("bar"))))); + AssignValueUpdate(StringFieldValue("bar")))))); } ArrayUpdateFixture::~ArrayUpdateFixture() = default; diff --git a/document/src/tests/testxml.cpp b/document/src/tests/testxml.cpp index 4d26be9da9c..8f1ce50f224 100644 --- a/document/src/tests/testxml.cpp +++ b/document/src/tests/testxml.cpp @@ -22,9 +22,7 @@ namespace { Document::UP createTestDocument(const DocumentTypeRepo& repo) { const DocumentType* type(repo.getDocumentType("testdoc")); - Document::UP - doc(new Document(*type, - DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/"))); + auto doc = std::make_unique(*type,DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/")); doc->setRepo(repo); std::string s("humlepungens buffer"); ByteBuffer bb(s.c_str(), s.size()); @@ -47,8 +45,7 @@ Document::UP createTestDocument(const DocumentTypeRepo& repo) val.add(rawVal3); doc->setValue(doc->getField("rawarrayattr"), val); - Document::UP doc2(new Document(*type, DocumentId( - "id:ns:testdoc::crawler/http://www.ntnu.no/2"))); + auto doc2 = std::make_unique(*type, DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/2")); doc2->setValue(doc2->getField("stringattr"), StringFieldValue("tjo hei paa du")); doc->setValue(doc->getField("docfield"), *doc2); @@ -61,19 +58,18 @@ createTestDocumentUpdate(const DocumentTypeRepo& repo) const DocumentType* type(repo.getDocumentType("testdoc")); DocumentId id("id:ns:testdoc::crawler/http://www.ntnu.no/"); - DocumentUpdate::UP up(new DocumentUpdate(repo, *type, id)); - up->addUpdate(FieldUpdate(type->getField("intattr")) - .addUpdate(AssignValueUpdate(IntFieldValue(7)))); - up->addUpdate(FieldUpdate(type->getField("stringattr")) - .addUpdate(AssignValueUpdate( - StringFieldValue("New value")))); - up->addUpdate(FieldUpdate(type->getField("arrayattr")) + auto up = std::make_unique(repo, *type, id); + up->addUpdate(std::move(FieldUpdate(type->getField("intattr")) + .addUpdate(AssignValueUpdate(IntFieldValue(7))))); + up->addUpdate(std::move(FieldUpdate(type->getField("stringattr")) + .addUpdate(AssignValueUpdate(StringFieldValue("New value"))))); + up->addUpdate(std::move(FieldUpdate(type->getField("arrayattr")) .addUpdate(AddValueUpdate(IntFieldValue(123))) - .addUpdate(AddValueUpdate(IntFieldValue(456)))); - up->addUpdate(FieldUpdate(type->getField("arrayattr")) + .addUpdate(AddValueUpdate(IntFieldValue(456))))); + up->addUpdate(std::move(FieldUpdate(type->getField("arrayattr")) .addUpdate(RemoveValueUpdate(IntFieldValue(123))) .addUpdate(RemoveValueUpdate(IntFieldValue(456))) - .addUpdate(RemoveValueUpdate(IntFieldValue(789)))); + .addUpdate(RemoveValueUpdate(IntFieldValue(789))))); return up; } diff --git a/document/src/vespa/document/update/documentupdate.cpp b/document/src/vespa/document/update/documentupdate.cpp index 2b831f951f8..89e275bf92d 100644 --- a/document/src/vespa/document/update/documentupdate.cpp +++ b/document/src/vespa/document/update/documentupdate.cpp @@ -122,9 +122,9 @@ void DocumentUpdate::ensureDeserialized() const { } DocumentUpdate& -DocumentUpdate::addUpdate(const FieldUpdate& update) { +DocumentUpdate::addUpdate(FieldUpdate &&update) { ensureDeserialized(); - _updates.push_back(update); + _updates.push_back(std::move(update)); reserialize(); return *this; } diff --git a/document/src/vespa/document/update/documentupdate.h b/document/src/vespa/document/update/documentupdate.h index 976c6337747..1afadff2827 100644 --- a/document/src/vespa/document/update/documentupdate.h +++ b/document/src/vespa/document/update/documentupdate.h @@ -87,7 +87,7 @@ public: */ void applyTo(Document& doc) const; - DocumentUpdate& addUpdate(const FieldUpdate& update); + DocumentUpdate& addUpdate(FieldUpdate && update); DocumentUpdate& addFieldPathUpdate(const FieldPathUpdate::CP& update); /** @return The list of updates. */ diff --git a/document/src/vespa/document/update/fieldupdate.cpp b/document/src/vespa/document/update/fieldupdate.cpp index 2db4f7eba2d..d0941acbfee 100644 --- a/document/src/vespa/document/update/fieldupdate.cpp +++ b/document/src/vespa/document/update/fieldupdate.cpp @@ -35,11 +35,10 @@ FieldUpdate::FieldUpdate(const DocumentTypeRepo& repo, const DataType & type, nb _updates.reserve(numUpdates); const DataType& dataType = _field.getDataType(); for(int i(0); i < numUpdates; i++) { - _updates.emplace_back(ValueUpdate::createInstance(repo, dataType, stream).release()); + _updates.emplace_back(ValueUpdate::createInstance(repo, dataType, stream)); } } -FieldUpdate::FieldUpdate(const FieldUpdate &) = default; FieldUpdate::~FieldUpdate() = default; bool @@ -53,6 +52,14 @@ FieldUpdate::operator==(const FieldUpdate& other) const return true; } + +FieldUpdate& +FieldUpdate::addUpdate(const ValueUpdate& update) { + update.checkCompatibility(_field); // May throw exception. + _updates.push_back(std::unique_ptr(update.clone())); + return *this; +} + void FieldUpdate::printXml(XmlOutputStream& xos) const { diff --git a/document/src/vespa/document/update/fieldupdate.h b/document/src/vespa/document/update/fieldupdate.h index 20cb739ee57..686c3a32d19 100644 --- a/document/src/vespa/document/update/fieldupdate.h +++ b/document/src/vespa/document/update/fieldupdate.h @@ -21,22 +21,19 @@ namespace document { class Document; class DocumentType; -class FieldUpdate : public vespalib::Identifiable +class FieldUpdate { - Field _field; - std::vector _updates; - using nbostream = vespalib::nbostream; - public: - typedef vespalib::CloneablePtr CP; + using nbostream = vespalib::nbostream; + using ValueUpdates = std::vector>; using XmlOutputStream = vespalib::xml::XmlOutputStream; FieldUpdate(const Field& field); - FieldUpdate(const FieldUpdate &); + FieldUpdate(const FieldUpdate &) = delete; FieldUpdate & operator = (const FieldUpdate &) = delete; FieldUpdate(FieldUpdate &&) = default; FieldUpdate & operator = (FieldUpdate &&) = default; - ~FieldUpdate() override; + ~FieldUpdate(); /** * This is a convenience function to construct a field update directly from @@ -56,18 +53,14 @@ public: * @param update A pointer to the value update to add to this. * @return A pointer to this. */ - FieldUpdate& addUpdate(const ValueUpdate& update) { - update.checkCompatibility(_field); // May throw exception. - _updates.push_back(ValueUpdate::CP(update.clone())); - return *this; - } + FieldUpdate& addUpdate(const ValueUpdate& update); const ValueUpdate& operator[](int index) const { return *_updates[index]; } ValueUpdate& operator[](int index) { return *_updates[index]; } size_t size() const { return _updates.size(); } /** @return The non-modifieable list of value updates to perform. */ - const std::vector& getUpdates() const { return _updates; } + const ValueUpdates & getUpdates() const { return _updates; } const Field& getField() const { return _field; } void applyTo(Document& doc) const; @@ -82,7 +75,9 @@ public: * @param buffer The stream that contains the serialized update object. */ void deserialize(const DocumentTypeRepo& repo, const DocumentType& type, nbostream& stream); - +private: + Field _field; + ValueUpdates _updates; }; } // document diff --git a/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp b/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp index 95d7822e17c..339c72864fa 100644 --- a/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp +++ b/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp @@ -665,8 +665,7 @@ TEST_F(ConformanceTest, testPutOlderDocumentVersion) EXPECT_TRUE(info2.getUsedSize() >= info1.getDocumentSize()); } - GetResult gr = spi->get(bucket, document::AllFields(), doc1->getId(), - context); + GetResult gr = spi->get(bucket, document::AllFields(), doc1->getId(), context); EXPECT_EQ(Result::ErrorType::NONE, gr.getErrorCode()); EXPECT_EQ(Timestamp(5), gr.getTimestamp()); @@ -684,8 +683,7 @@ TEST_F(ConformanceTest, testPutDuplicate) Bucket bucket(makeSpiBucket(BucketId(8, 0x01))); Document::SP doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1); spi->createBucket(bucket, context); - EXPECT_EQ(Result(), - spi->put(bucket, Timestamp(3), doc1, context)); + EXPECT_EQ(Result(), spi->put(bucket, Timestamp(3), doc1, context)); BucketChecksum checksum; { @@ -693,8 +691,7 @@ TEST_F(ConformanceTest, testPutDuplicate) EXPECT_EQ(1, (int)info.getDocumentCount()); checksum = info.getChecksum(); } - EXPECT_EQ(Result(), - spi->put(bucket, Timestamp(3), doc1, context)); + EXPECT_EQ(Result(), spi->put(bucket, Timestamp(3), doc1, context)); { const BucketInfo info = spi->getBucketInfo(bucket).getBucketInfo(); @@ -730,10 +727,7 @@ TEST_F(ConformanceTest, testRemove) } // Add a remove entry - RemoveResult result2 = spi->remove(bucket, - Timestamp(5), - doc1->getId(), - context); + RemoveResult result2 = spi->remove(bucket, Timestamp(5), doc1->getId(), context); { const BucketInfo info = spi->getBucketInfo(bucket).getBucketInfo(); @@ -753,10 +747,7 @@ TEST_F(ConformanceTest, testRemove) } // Result tagged as document not found - RemoveResult result3 = spi->remove(bucket, - Timestamp(7), - doc1->getId(), - context); + RemoveResult result3 = spi->remove(bucket, Timestamp(7), doc1->getId(), context); { const BucketInfo info = spi->getBucketInfo(bucket).getBucketInfo(); @@ -769,10 +760,7 @@ TEST_F(ConformanceTest, testRemove) EXPECT_TRUE(!result4.hasError()); - RemoveResult result5 = spi->remove(bucket, - Timestamp(9), - doc1->getId(), - context); + RemoveResult result5 = spi->remove(bucket, Timestamp(9), doc1->getId(), context); { const BucketInfo info = spi->getBucketInfo(bucket).getBucketInfo(); @@ -782,10 +770,7 @@ TEST_F(ConformanceTest, testRemove) EXPECT_TRUE(!result5.hasError()); } - GetResult getResult = spi->get(bucket, - document::AllFields(), - doc1->getId(), - context); + GetResult getResult = spi->get(bucket, document::AllFields(), doc1->getId(), context); EXPECT_EQ(Result::ErrorType::NONE, getResult.getErrorCode()); EXPECT_EQ(Timestamp(9), getResult.getTimestamp()); @@ -843,10 +828,7 @@ TEST_F(ConformanceTest, testRemoveMerge) // Remove a document that does not exist { - RemoveResult removeResult = spi->remove(bucket, - Timestamp(10), - removeId, - context); + RemoveResult removeResult = spi->remove(bucket, Timestamp(10), removeId, context); EXPECT_EQ(Result::ErrorType::NONE, removeResult.getErrorCode()); EXPECT_EQ(false, removeResult.wasFound()); } @@ -869,10 +851,7 @@ TEST_F(ConformanceTest, testRemoveMerge) } // Add a _newer_ remove for the same document ID we already removed { - RemoveResult removeResult = spi->remove(bucket, - Timestamp(11), - removeId, - context); + RemoveResult removeResult = spi->remove(bucket, Timestamp(11), removeId, context); EXPECT_EQ(Result::ErrorType::NONE, removeResult.getErrorCode()); EXPECT_EQ(false, removeResult.wasFound()); } @@ -896,10 +875,7 @@ TEST_F(ConformanceTest, testRemoveMerge) // It may or may not be present in a subsequent iteration, but the // newest timestamp must still be present. { - RemoveResult removeResult = spi->remove(bucket, - Timestamp(7), - removeId, - context); + RemoveResult removeResult = spi->remove(bucket, Timestamp(7), removeId, context); EXPECT_EQ(Result::ErrorType::NONE, removeResult.getErrorCode()); EXPECT_EQ(false, removeResult.wasFound()); } @@ -937,29 +913,24 @@ TEST_F(ConformanceTest, testUpdate) std::shared_ptr assignUpdate(new document::AssignValueUpdate(document::IntFieldValue(42))); document::FieldUpdate fieldUpdate(docType->getField("headerval")); fieldUpdate.addUpdate(*assignUpdate); - update->addUpdate(fieldUpdate); + update->addUpdate(std::move(fieldUpdate)); { - UpdateResult result = spi->update(bucket, Timestamp(3), update, - context); + UpdateResult result = spi->update(bucket, Timestamp(3), update, context); EXPECT_EQ(Result(), Result(result)); EXPECT_EQ(Timestamp(0), result.getExistingTimestamp()); } spi->put(bucket, Timestamp(3), doc1, context); { - UpdateResult result = spi->update(bucket, Timestamp(4), update, - context); + UpdateResult result = spi->update(bucket, Timestamp(4), update, context); EXPECT_EQ(Result::ErrorType::NONE, result.getErrorCode()); EXPECT_EQ(Timestamp(3), result.getExistingTimestamp()); } { - GetResult result = spi->get(bucket, - document::AllFields(), - doc1->getId(), - context); + GetResult result = spi->get(bucket, document::AllFields(), doc1->getId(), context); EXPECT_EQ(Result::ErrorType::NONE, result.getErrorCode()); EXPECT_EQ(Timestamp(4), result.getTimestamp()); @@ -972,10 +943,7 @@ TEST_F(ConformanceTest, testUpdate) spi->remove(bucket, Timestamp(5), doc1->getId(), context); { - GetResult result = spi->get(bucket, - document::AllFields(), - doc1->getId(), - context); + GetResult result = spi->get(bucket, document::AllFields(), doc1->getId(), context); EXPECT_EQ(Result::ErrorType::NONE, result.getErrorCode()); EXPECT_EQ(Timestamp(5), result.getTimestamp()); @@ -984,8 +952,7 @@ TEST_F(ConformanceTest, testUpdate) } { - UpdateResult result = spi->update(bucket, Timestamp(6), update, - context); + UpdateResult result = spi->update(bucket, Timestamp(6), update, context); EXPECT_EQ(Result::ErrorType::NONE, result.getErrorCode()); EXPECT_EQ(Timestamp(0), result.getExistingTimestamp()); diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp index fdf75bbd726..a95d3f7ccca 100644 --- a/searchcore/src/tests/proton/attribute/attribute_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp @@ -482,10 +482,10 @@ TEST_F(AttributeWriterTest, handles_update) DocBuilder idb(schema); const document::DocumentType &dt(idb.getDocumentType()); DocumentUpdate upd(*idb.getDocumentTypeRepo(), dt, DocumentId("id:ns:searchdocument::1")); - upd.addUpdate(FieldUpdate(upd.getType().getField("a1")) - .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 5))); - upd.addUpdate(FieldUpdate(upd.getType().getField("a2")) - .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10))); + upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1")) + .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 5)))); + upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a2")) + .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10)))); DummyFieldUpdateCallback onUpdate; update(2, upd, 1, onUpdate); @@ -527,8 +527,8 @@ TEST_F(AttributeWriterTest, handles_predicate_update) const document::DocumentType &dt(idb.getDocumentType()); DocumentUpdate upd(*idb.getDocumentTypeRepo(), dt, DocumentId("id:ns:searchdocument::1")); PredicateFieldValue new_value(builder.feature("foo").value("bar").build()); - upd.addUpdate(FieldUpdate(upd.getType().getField("a1")) - .addUpdate(AssignValueUpdate(new_value))); + upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1")) + .addUpdate(AssignValueUpdate(new_value)))); PredicateIndex &index = static_cast(*a1).getIndex(); EXPECT_EQ(1u, index.getZeroConstraintDocs().size()); @@ -728,8 +728,8 @@ TEST_F(AttributeWriterTest, handles_tensor_assign_update) TensorDataType xySparseTensorDataType(vespalib::eval::ValueType::from_spec(sparse_tensor)); TensorFieldValue new_value(xySparseTensorDataType); new_value = SimpleValue::from_value(*new_tensor); - upd.addUpdate(FieldUpdate(upd.getType().getField("a1")) - .addUpdate(AssignValueUpdate(new_value))); + upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1")) + .addUpdate(AssignValueUpdate(new_value)))); DummyFieldUpdateCallback onUpdate; update(2, upd, 1, onUpdate); EXPECT_EQ(2u, a1->getNumDocs()); @@ -938,7 +938,7 @@ public: TensorDataType tensor_type(vespalib::eval::ValueType::from_spec(dense_tensor)); TensorFieldValue tensor_value(tensor_type); tensor_value= SimpleValue::from_value(*tensor); - upd->addUpdate(FieldUpdate(upd->getType().getField("a1")).addUpdate(AssignValueUpdate(tensor_value))); + upd->addUpdate(std::move(FieldUpdate(upd->getType().getField("a1")).addUpdate(AssignValueUpdate(tensor_value)))); return upd; } void expect_shared_executor_tasks(size_t exp_accepted_tasks) { diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp index 4040d69270f..c3275d51a1e 100644 --- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp @@ -346,9 +346,7 @@ struct UpdateContext { fieldValue->assign(document::StringFieldValue("new value")); } document::AssignValueUpdate assignValueUpdate(*fieldValue); - document::FieldUpdate fieldUpdate(field); - fieldUpdate.addUpdate(assignValueUpdate); - update->addUpdate(fieldUpdate); + update->addUpdate(std::move(document::FieldUpdate(field).addUpdate(assignValueUpdate))); } }; @@ -773,11 +771,11 @@ TEST_F("require that update with a fieldpath update will be rejected", SchemaCon TEST_F("require that all value updates will be inspected before rejected", SchemaContext) { const DocumentType *docType = f.getRepo()->getDocumentType(f.getDocType().getName()); auto docUpdate = std::make_unique(*f.getRepo(), *docType, DocumentId("id:ns:" + docType->getName() + "::1")); - docUpdate->addUpdate(FieldUpdate(docType->getField("i1")).addUpdate(ClearValueUpdate())); + docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(ClearValueUpdate()))); EXPECT_FALSE(FeedRejectHelper::mustReject(*docUpdate)); - docUpdate->addUpdate(FieldUpdate(docType->getField("i1")).addUpdate(ClearValueUpdate())); + docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(ClearValueUpdate()))); EXPECT_FALSE(FeedRejectHelper::mustReject(*docUpdate)); - docUpdate->addUpdate(FieldUpdate(docType->getField("i1")).addUpdate(AssignValueUpdate(StringFieldValue()))); + docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(AssignValueUpdate(StringFieldValue())))); EXPECT_TRUE(FeedRejectHelper::mustReject(*docUpdate)); } diff --git a/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp b/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp index d79b46b2e08..2490fac783a 100644 --- a/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp +++ b/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -122,8 +121,8 @@ public: auto makeUpdate() { auto upd(std::make_shared(*_repo, _docType, docId)); - upd->addUpdate(FieldUpdate(upd->getType().getField("string")). - addUpdate(AssignValueUpdate(StringFieldValue("newval")))); + upd->addUpdate(std::move(FieldUpdate(upd->getType().getField("string")). + addUpdate(AssignValueUpdate(StringFieldValue("newval"))))); return upd; } auto makeDoc() { diff --git a/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp b/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp index 95593307ba2..2c72b37bc8d 100644 --- a/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp +++ b/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp @@ -25,6 +25,8 @@ using document::BucketSpace; using document::Document; using document::DocumentId; using document::DocumentType; +using document::DocumentTypeRepo; +using document::DocumentUpdate; using document::test::makeBucketSpace; using search::DocumentMetaData; using storage::spi::Bucket; @@ -56,19 +58,19 @@ createDocType(const vespalib::string &name, int32_t id) } -document::Document::SP +Document::SP createDoc(const DocumentType &docType, const DocumentId &docId) { - return std::make_shared(docType, docId); + return std::make_shared(docType, docId); } -document::DocumentUpdate::SP +DocumentUpdate::SP createUpd(const DocumentType& docType, const DocumentId &docId) { - static std::vector> repoList; - repoList.emplace_back(std::make_unique(docType)); - return std::make_shared(*repoList.back(), docType, docId); + static std::vector> repoList; + repoList.emplace_back(std::make_unique(docType)); + return std::make_shared(*repoList.back(), docType, docId); } storage::spi::ClusterState @@ -105,14 +107,14 @@ createClusterState(const storage::lib::State& nodeState = storage::lib::State::U struct MyDocumentRetriever : DocumentRetrieverBaseForTest { - document::DocumentTypeRepo repo; + DocumentTypeRepo repo; const Document *document; Timestamp timestamp; DocumentId &last_doc_id; MyDocumentRetriever(const Document *d, Timestamp ts, DocumentId &last_id) : repo(), document(d), timestamp(ts), last_doc_id(last_id) {} - const document::DocumentTypeRepo &getDocumentTypeRepo() const override { + const DocumentTypeRepo &getDocumentTypeRepo() const override { return repo; } void getBucketMetaData(const storage::spi::Bucket &, search::DocumentMetaData::Vector &v) const override { @@ -123,11 +125,11 @@ struct MyDocumentRetriever : DocumentRetrieverBaseForTest { DocumentMetaData getDocumentMetaData(const DocumentId &id) const override { last_doc_id = id; if (document != nullptr) { - return DocumentMetaData(1, timestamp, document::BucketId(1), document->getId().getGlobalId()); + return DocumentMetaData(1, timestamp, BucketId(1), document->getId().getGlobalId()); } return DocumentMetaData(); } - document::Document::UP getFullDocument(search::DocumentIdT) const override { + Document::UP getFullDocument(search::DocumentIdT) const override { if (document != nullptr) { return Document::UP(document->clone()); } @@ -271,7 +273,7 @@ struct MyHandler : public IPersistenceHandler, IBucketFreezer { resultHandler.handle(BucketIdListResult()); } - void handlePopulateActiveBuckets(document::BucketId::List buckets, IGenericResultHandler &resultHandler) override { + void handlePopulateActiveBuckets(BucketId::List buckets, IGenericResultHandler &resultHandler) override { (void) buckets; resultHandler.handle(Result()); } @@ -317,10 +319,10 @@ DocumentId docId3("id:type3:type3::1"); Document::SP doc1(createDoc(type1, docId1)); Document::SP doc2(createDoc(type2, docId2)); Document::SP doc3(createDoc(type3, docId3)); -document::DocumentUpdate::SP upd1(createUpd(type1, docId1)); -document::DocumentUpdate::SP upd2(createUpd(type2, docId2)); -document::DocumentUpdate::SP upd3(createUpd(type3, docId3)); -document::DocumentUpdate::SP bad_id_upd(createUpd(type1, docId2)); +DocumentUpdate::SP upd1(createUpd(type1, docId1)); +DocumentUpdate::SP upd2(createUpd(type2, docId2)); +DocumentUpdate::SP upd3(createUpd(type3, docId3)); +DocumentUpdate::SP bad_id_upd(createUpd(type1, docId2)); BucketId bckId1(1); BucketId bckId2(2); BucketId bckId3(3); @@ -518,10 +520,8 @@ TEST_F("require that update is rejected if resource limit is reached", SimpleFix DocumentType type(createDocType("type_with_one_string", 1)); document::Field field("string", 1, *document::DataType::STRING); type.addField(field); - document::DocumentUpdate::SP upd = createUpd(type, docId1); - document::FieldUpdate fUpd(field); - fUpd.addUpdate(document::AssignValueUpdate(document::StringFieldValue("new value"))); - upd->addUpdate(fUpd); + DocumentUpdate::SP upd = createUpd(type, docId1); + upd->addUpdate(std::move(document::FieldUpdate(field).addUpdate(document::AssignValueUpdate(document::StringFieldValue("new value"))))); EXPECT_EQUAL( Result(Result::ErrorType::RESOURCE_EXHAUSTED, diff --git a/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp b/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp index 56cea8db741..ae1b9ec7fe3 100644 --- a/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp +++ b/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp @@ -1,17 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "bm_feed.h" -#include "avg_sampler.h" #include "bm_feed_operation.h" #include "bm_feed_params.h" #include "bm_range.h" #include "bucket_selector.h" -#include "pending_tracker.h" #include "i_bm_feed_handler.h" #include #include #include -#include #include #include #include @@ -74,7 +71,7 @@ BmFeed::make_document_update(uint32_t n, uint32_t i) const { auto id = make_document_id(n, i); auto document_update = std::make_unique(*_repo, *_document_type, id); - document_update->addUpdate(FieldUpdate(_field).addUpdate(AssignValueUpdate(IntFieldValue(15)))); + document_update->addUpdate(std::move(FieldUpdate(_field).addUpdate(AssignValueUpdate(IntFieldValue(15))))); return document_update; } diff --git a/storage/src/tests/distributor/externaloperationhandlertest.cpp b/storage/src/tests/distributor/externaloperationhandlertest.cpp index 27855091257..5aa5845ac4c 100644 --- a/storage/src/tests/distributor/externaloperationhandlertest.cpp +++ b/storage/src/tests/distributor/externaloperationhandlertest.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -597,7 +596,7 @@ TEST_F(ExternalOperationHandlerTest, non_trivial_updates_are_rejected_if_feed_is const auto* doc_type = _testDocMan.getTypeRepo().getDocumentType("testdoctype1"); document::FieldUpdate upd(doc_type->getField("title")); upd.addUpdate(document::AssignValueUpdate(document::StringFieldValue("new value"))); - cmd->getUpdate()->addUpdate(upd); + cmd->getUpdate()->addUpdate(std::move(upd)); ASSERT_NO_FATAL_FAILURE(start_operation_verify_rejected(std::move(cmd))); EXPECT_EQ("ReturnCode(NO_SPACE, External feed is blocked due to resource exhaustion: full disk)", diff --git a/storage/src/tests/distributor/twophaseupdateoperationtest.cpp b/storage/src/tests/distributor/twophaseupdateoperationtest.cpp index fae2a3d0982..7a7e53a1d2c 100644 --- a/storage/src/tests/distributor/twophaseupdateoperationtest.cpp +++ b/storage/src/tests/distributor/twophaseupdateoperationtest.cpp @@ -297,7 +297,7 @@ TwoPhaseUpdateOperationTest::sendUpdate(const std::string& bucketState, document::DocumentId("id:ns:" + _doc_type->getName() + "::1")); document::FieldUpdate fup(_doc_type->getField("headerval")); fup.addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10)); - update->addUpdate(fup); + update->addUpdate(std::move(fup)); } else { // Create an update to a different doctype than the one returned as // part of the Get. Just a sneaky way to force an eval error. @@ -307,7 +307,7 @@ TwoPhaseUpdateOperationTest::sendUpdate(const std::string& bucketState, document::DocumentId("id:ns:" + _doc_type->getName() + "::1")); document::FieldUpdate fup(badDocType->getField("onlyinchild")); fup.addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10)); - update->addUpdate(fup); + update->addUpdate(std::move(fup)); } update->setCreateIfNonExistent(options._createIfNonExistent); diff --git a/storage/src/tests/persistence/persistencetestutils.cpp b/storage/src/tests/persistence/persistencetestutils.cpp index 6974319dc72..0adeff5bc34 100644 --- a/storage/src/tests/persistence/persistencetestutils.cpp +++ b/storage/src/tests/persistence/persistencetestutils.cpp @@ -226,9 +226,7 @@ PersistenceTestUtils::createBodyUpdate(const document::DocumentId& docId, const const DocumentType* docType(getTypeRepo()->getDocumentType("testdoctype1")); auto update = std::make_shared(*getTypeRepo(), *docType, docId); auto assignUpdate = std::make_shared(updateValue); - document::FieldUpdate fieldUpdate(docType->getField("content")); - fieldUpdate.addUpdate(*assignUpdate); - update->addUpdate(fieldUpdate); + update->addUpdate(std::move(document::FieldUpdate(docType->getField("content")).addUpdate(*assignUpdate))); return update; } @@ -238,9 +236,7 @@ PersistenceTestUtils::createHeaderUpdate(const document::DocumentId& docId, cons const DocumentType* docType(getTypeRepo()->getDocumentType("testdoctype1")); auto update = std::make_shared(*getTypeRepo(), *docType, docId); auto assignUpdate = std::make_shared(updateValue); - document::FieldUpdate fieldUpdate(docType->getField("headerval")); - fieldUpdate.addUpdate(*assignUpdate); - update->addUpdate(fieldUpdate); + update->addUpdate(std::move(document::FieldUpdate(docType->getField("headerval")).addUpdate(*assignUpdate))); return update; } diff --git a/storage/src/tests/persistence/testandsettest.cpp b/storage/src/tests/persistence/testandsettest.cpp index 816fd7871d3..267569b0bc5 100644 --- a/storage/src/tests/persistence/testandsettest.cpp +++ b/storage/src/tests/persistence/testandsettest.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -160,9 +159,7 @@ std::shared_ptr TestAndSetTest::conditional_update_test(bool createIfMissing, api::Timestamp updateTimestamp) { auto docUpdate = std::make_shared(_env->_testDocMan.getTypeRepo(), testDoc->getType(), testDocId); - auto fieldUpdate = document::FieldUpdate(testDoc->getField("content")); - fieldUpdate.addUpdate(document::AssignValueUpdate(NEW_CONTENT)); - docUpdate->addUpdate(fieldUpdate); + docUpdate->addUpdate(std::move(document::FieldUpdate(testDoc->getField("content")).addUpdate(document::AssignValueUpdate(NEW_CONTENT)))); docUpdate->setCreateIfNonExistent(createIfMissing); auto updateUp = std::make_unique(BUCKET, docUpdate, updateTimestamp); diff --git a/storageapi/src/tests/mbusprot/storageprotocoltest.cpp b/storageapi/src/tests/mbusprot/storageprotocoltest.cpp index b927c045f51..a510ed832e8 100644 --- a/storageapi/src/tests/mbusprot/storageprotocoltest.cpp +++ b/storageapi/src/tests/mbusprot/storageprotocoltest.cpp @@ -246,9 +246,7 @@ TEST_P(StorageProtocolTest, update) { auto update = std::make_shared( _docMan.getTypeRepo(), *_testDoc->getDataType(), _testDoc->getId()); auto assignUpdate = std::make_shared(document::IntFieldValue(17)); - document::FieldUpdate fieldUpdate(_testDoc->getField("headerval")); - fieldUpdate.addUpdate(*assignUpdate); - update->addUpdate(fieldUpdate); + update->addUpdate(std::move(document::FieldUpdate(_testDoc->getField("headerval")).addUpdate(*assignUpdate))); update->addFieldPathUpdate(document::FieldPathUpdate::CP( new document::RemoveFieldPathUpdate("headerval", "testdoctype1.headerval > 0"))); -- cgit v1.2.3