summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-28 06:42:13 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-03-28 10:08:43 +0000
commit02b5efaa3bbc043e50e2c64b968241f842c3cffc (patch)
treeb9f9ea83f0dd49656791439322d5ba3d3b6be0b9 /searchcore
parentbb59611ce9611986ee97f19d2bb725dc1d160074 (diff)
Avoid the need for clone by using unique_ptr.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_test.cpp10
-rw-r--r--searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp51
-rw-r--r--searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp9
-rw-r--r--searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp2
-rw-r--r--searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp2
-rw-r--r--searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp2
6 files changed, 37 insertions, 39 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp
index a95d3f7ccca..e64045853d4 100644
--- a/searchcore/src/tests/proton/attribute/attribute_test.cpp
+++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp
@@ -483,9 +483,9 @@ TEST_F(AttributeWriterTest, handles_update)
const document::DocumentType &dt(idb.getDocumentType());
DocumentUpdate upd(*idb.getDocumentTypeRepo(), dt, DocumentId("id:ns:searchdocument::1"));
upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1"))
- .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 5))));
+ .addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 5))));
upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a2"))
- .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10))));
+ .addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10))));
DummyFieldUpdateCallback onUpdate;
update(2, upd, 1, onUpdate);
@@ -528,7 +528,7 @@ TEST_F(AttributeWriterTest, handles_predicate_update)
DocumentUpdate upd(*idb.getDocumentTypeRepo(), dt, DocumentId("id:ns:searchdocument::1"));
PredicateFieldValue new_value(builder.feature("foo").value("bar").build());
upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1"))
- .addUpdate(AssignValueUpdate(new_value))));
+ .addUpdate(std::make_unique<AssignValueUpdate>(new_value))));
PredicateIndex &index = static_cast<PredicateAttribute &>(*a1).getIndex();
EXPECT_EQ(1u, index.getZeroConstraintDocs().size());
@@ -729,7 +729,7 @@ TEST_F(AttributeWriterTest, handles_tensor_assign_update)
TensorFieldValue new_value(xySparseTensorDataType);
new_value = SimpleValue::from_value(*new_tensor);
upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1"))
- .addUpdate(AssignValueUpdate(new_value))));
+ .addUpdate(std::make_unique<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(std::move(FieldUpdate(upd->getType().getField("a1")).addUpdate(AssignValueUpdate(tensor_value))));
+ upd->addUpdate(std::move(FieldUpdate(upd->getType().getField("a1")).addUpdate(std::make_unique<AssignValueUpdate>(tensor_value))));
return upd;
}
void expect_shared_executor_tasks(size_t exp_accepted_tasks) {
diff --git a/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp b/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp
index 924abc81711..20584a2a1fb 100644
--- a/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp
+++ b/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp
@@ -97,29 +97,28 @@ struct Fixture {
{
}
- void applyValueUpdate(AttributeVector & vec, uint32_t docId, const ValueUpdate & upd) {
+ void applyValueUpdate(AttributeVector & vec, uint32_t docId, std::unique_ptr<ValueUpdate> upd) {
FieldUpdate fupd(docType->getField(vec.getName()));
- fupd.addUpdate(upd);
+ fupd.addUpdate(std::move(upd));
search::AttributeUpdater::handleUpdate(vec, docId, fupd);
vec.commit();
}
void applyArrayUpdates(AttributeVector & vec, const FieldValue & assign,
const FieldValue & first, const FieldValue & second) {
- applyValueUpdate(vec, 0, AssignValueUpdate(assign));
- applyValueUpdate(vec, 1, AddValueUpdate(second));
- applyValueUpdate(vec, 2, RemoveValueUpdate(first));
- applyValueUpdate(vec, 3, ClearValueUpdate());
+ applyValueUpdate(vec, 0, std::make_unique<AssignValueUpdate>(assign));
+ applyValueUpdate(vec, 1, std::make_unique<AddValueUpdate>(second));
+ applyValueUpdate(vec, 2, std::make_unique<RemoveValueUpdate>(first));
+ applyValueUpdate(vec, 3, std::make_unique<ClearValueUpdate>());
}
void applyWeightedSetUpdates(AttributeVector & vec, const FieldValue & assign,
const FieldValue & first, const FieldValue & second) {
- applyValueUpdate(vec, 0, AssignValueUpdate(assign));
- applyValueUpdate(vec, 1, AddValueUpdate(second, 20));
- applyValueUpdate(vec, 2, RemoveValueUpdate(first));
- applyValueUpdate(vec, 3, ClearValueUpdate());
- ArithmeticValueUpdate arithmetic(ArithmeticValueUpdate::Add, 10);
- applyValueUpdate(vec, 4, MapValueUpdate(first, arithmetic));
+ applyValueUpdate(vec, 0, std::make_unique<AssignValueUpdate>(assign));
+ applyValueUpdate(vec, 1, std::make_unique<AddValueUpdate>(second, 20));
+ applyValueUpdate(vec, 2, std::make_unique<RemoveValueUpdate>(first));
+ applyValueUpdate(vec, 3, std::make_unique<ClearValueUpdate>());
+ applyValueUpdate(vec, 4, std::make_unique<MapValueUpdate>(first, std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10)));
}
};
@@ -207,9 +206,9 @@ TEST_F("require that single attributes are updated", Fixture)
AttributePtr vec = create<int32_t, IntegerAttribute>(3, 32, 0,
"in1/int",
Config(bt, ct));
- f.applyValueUpdate(*vec, 0, AssignValueUpdate(IntFieldValue(64)));
- f.applyValueUpdate(*vec, 1, ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10));
- f.applyValueUpdate(*vec, 2, ClearValueUpdate());
+ f.applyValueUpdate(*vec, 0, std::make_unique<AssignValueUpdate>(IntFieldValue(64)));
+ f.applyValueUpdate(*vec, 1, std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10));
+ f.applyValueUpdate(*vec, 2, std::make_unique<ClearValueUpdate>());
EXPECT_EQUAL(3u, vec->getNumDocs());
EXPECT_TRUE(check(vec, 0, std::vector<WeightedInt>{WeightedInt(64)}));
EXPECT_TRUE(check(vec, 1, std::vector<WeightedInt>{WeightedInt(42)}));
@@ -221,9 +220,9 @@ TEST_F("require that single attributes are updated", Fixture)
"in1/float",
Config(bt,
ct));
- f.applyValueUpdate(*vec, 0, AssignValueUpdate(FloatFieldValue(77.7f)));
- f.applyValueUpdate(*vec, 1, ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10));
- f.applyValueUpdate(*vec, 2, ClearValueUpdate());
+ f.applyValueUpdate(*vec, 0, std::make_unique<AssignValueUpdate>(FloatFieldValue(77.7f)));
+ f.applyValueUpdate(*vec, 1, std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10));
+ f.applyValueUpdate(*vec, 2, std::make_unique<ClearValueUpdate>());
EXPECT_EQUAL(3u, vec->getNumDocs());
EXPECT_TRUE(check(vec, 0, std::vector<WeightedFloat>{WeightedFloat(77.7f)}));
EXPECT_TRUE(check(vec, 1, std::vector<WeightedFloat>{WeightedFloat(65.5f)}));
@@ -235,8 +234,8 @@ TEST_F("require that single attributes are updated", Fixture)
"in1/string",
Config(bt,
ct));
- f.applyValueUpdate(*vec, 0, AssignValueUpdate(StringFieldValue("second")));
- f.applyValueUpdate(*vec, 2, ClearValueUpdate());
+ f.applyValueUpdate(*vec, 0, std::make_unique<AssignValueUpdate>(StringFieldValue("second")));
+ f.applyValueUpdate(*vec, 2, std::make_unique<ClearValueUpdate>());
EXPECT_EQUAL(3u, vec->getNumDocs());
EXPECT_TRUE(check(vec, 0, std::vector<WeightedString>{WeightedString("second")}));
EXPECT_TRUE(check(vec, 1, std::vector<WeightedString>{WeightedString("first")}));
@@ -255,8 +254,8 @@ TEST_F("require that single attributes are updated", Fixture)
asReferenceAttribute(*vec).update(docId, toGid(doc1));
}
vec->commit();
- f.applyValueUpdate(*vec, 0, AssignValueUpdate(ReferenceFieldValue(dynamic_cast<const ReferenceDataType &>(f.docType->getField("ref").getDataType()), DocumentId(doc2))));
- f.applyValueUpdate(*vec, 2, ClearValueUpdate());
+ f.applyValueUpdate(*vec, 0, std::make_unique<AssignValueUpdate>(ReferenceFieldValue(dynamic_cast<const ReferenceDataType &>(f.docType->getField("ref").getDataType()), DocumentId(doc2))));
+ f.applyValueUpdate(*vec, 2, std::make_unique<ClearValueUpdate>());
EXPECT_EQUAL(3u, vec->getNumDocs());
TEST_DO(assertRef(*vec, doc2, 0));
TEST_DO(assertRef(*vec, doc1, 1));
@@ -453,7 +452,7 @@ TEST_F("require that tensor modify update is applied",
{
f.setTensor(TensorSpec(f.type).add({{"x", 0}}, 3).add({{"x", 1}}, 5));
f.applyValueUpdate(*f.attribute, 1,
- TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE,
+ std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::REPLACE,
makeTensorFieldValue(TensorSpec("tensor(x{})").add({{"x", "0"}}, 7))));
f.assertTensor(TensorSpec(f.type).add({{"x", 0}}, 7).add({{"x", 1}}, 5));
}
@@ -463,7 +462,7 @@ TEST_F("require that tensor add update is applied",
{
f.setTensor(TensorSpec(f.type).add({{"x", "a"}}, 2));
f.applyValueUpdate(*f.attribute, 1,
- TensorAddUpdate(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3))));
+ std::make_unique<TensorAddUpdate>(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3))));
f.assertTensor(TensorSpec(f.type).add({{"x", "a"}}, 3));
}
@@ -471,7 +470,7 @@ TEST_F("require that tensor add update to non-existing tensor creates empty tens
TensorFixture<SerializedFastValueAttribute>("tensor(x{})", "sparse_tensor"))
{
f.applyValueUpdate(*f.attribute, 1,
- TensorAddUpdate(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3))));
+ std::make_unique<TensorAddUpdate>(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3))));
f.assertTensor(TensorSpec(f.type).add({{"x", "a"}}, 3));
}
@@ -480,7 +479,7 @@ TEST_F("require that tensor remove update is applied",
{
f.setTensor(TensorSpec(f.type).add({{"x", "a"}}, 2).add({{"x", "b"}}, 3));
f.applyValueUpdate(*f.attribute, 1,
- TensorRemoveUpdate(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "b"}}, 1))));
+ std::make_unique<TensorRemoveUpdate>(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "b"}}, 1))));
f.assertTensor(TensorSpec(f.type).add({{"x", "a"}}, 2));
}
diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
index c3275d51a1e..8affdde8562 100644
--- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
+++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
@@ -345,8 +345,7 @@ struct UpdateContext {
} else {
fieldValue->assign(document::StringFieldValue("new value"));
}
- document::AssignValueUpdate assignValueUpdate(*fieldValue);
- update->addUpdate(std::move(document::FieldUpdate(field).addUpdate(assignValueUpdate)));
+ update->addUpdate(std::move(document::FieldUpdate(field).addUpdate(std::make_unique<document::AssignValueUpdate>(*fieldValue))));
}
};
@@ -771,11 +770,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<DocumentUpdate>(*f.getRepo(), *docType, DocumentId("id:ns:" + docType->getName() + "::1"));
- docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(ClearValueUpdate())));
+ docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(std::make_unique<ClearValueUpdate>())));
EXPECT_FALSE(FeedRejectHelper::mustReject(*docUpdate));
- docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(ClearValueUpdate())));
+ docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(std::make_unique<ClearValueUpdate>())));
EXPECT_FALSE(FeedRejectHelper::mustReject(*docUpdate));
- docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(AssignValueUpdate(StringFieldValue()))));
+ docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(std::make_unique<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 2490fac783a..36920f52254 100644
--- a/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp
+++ b/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp
@@ -122,7 +122,7 @@ public:
auto makeUpdate() {
auto upd(std::make_shared<DocumentUpdate>(*_repo, _docType, docId));
upd->addUpdate(std::move(FieldUpdate(upd->getType().getField("string")).
- addUpdate(AssignValueUpdate(StringFieldValue("newval")))));
+ addUpdate(std::make_unique<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 2c72b37bc8d..7f35e05dfb6 100644
--- a/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp
+++ b/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp
@@ -521,7 +521,7 @@ TEST_F("require that update is rejected if resource limit is reached", SimpleFix
document::Field field("string", 1, *document::DataType::STRING);
type.addField(field);
DocumentUpdate::SP upd = createUpd(type, docId1);
- upd->addUpdate(std::move(document::FieldUpdate(field).addUpdate(document::AssignValueUpdate(document::StringFieldValue("new value")))));
+ upd->addUpdate(std::move(document::FieldUpdate(field).addUpdate(std::make_unique<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 ae1b9ec7fe3..c8a7f3336e0 100644
--- a/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp
+++ b/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp
@@ -71,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<DocumentUpdate>(*_repo, *_document_type, id);
- document_update->addUpdate(std::move(FieldUpdate(_field).addUpdate(AssignValueUpdate(IntFieldValue(15)))));
+ document_update->addUpdate(std::move(FieldUpdate(_field).addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(15)))));
return document_update;
}