diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-29 13:51:55 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-29 13:51:55 +0000 |
commit | 11f15ddddb70427d1b571d76ca6ef734a1f15a0f (patch) | |
tree | 8a65f6fe9c47acefce648e5cdd1a91cfa832c569 /document | |
parent | 1cd2c6a3ba9e392c00b91bfe3cf1215a80c6679f (diff) |
Minor simplifications after PR feedback.
Diffstat (limited to 'document')
11 files changed, 31 insertions, 30 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index 70ebd9bd7a2..6644fec2da0 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -141,7 +141,7 @@ DocumentUpdate::SP DocumentSelectParserTest::createUpdate( doc->addUpdate(FieldUpdate(doc->getType().getField("headerval")) .addUpdate(std::make_unique<AssignValueUpdate>(std::make_unique<IntFieldValue>(hint)))); doc->addUpdate(FieldUpdate(doc->getType().getField("hstringval")) - .addUpdate(std::make_unique<AssignValueUpdate>(std::make_unique<StringFieldValue>(hstr)))); + .addUpdate(std::make_unique<AssignValueUpdate>(StringFieldValue::make(hstr)))); return doc; } diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index 27a9791b95c..40f398ee93e 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -255,8 +255,8 @@ TEST(DocumentUpdateTest, testUpdateArray) // Append array field DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(FieldUpdate(doc->getField("tags")) - .addUpdate(std::make_unique<AddValueUpdate>(std::make_unique<StringFieldValue>("another"))) - .addUpdate(std::make_unique<AddValueUpdate>(std::make_unique<StringFieldValue>("tag")))) + .addUpdate(std::make_unique<AddValueUpdate>(StringFieldValue::make("another"))) + .addUpdate(std::make_unique<AddValueUpdate>(StringFieldValue::make("tag")))) .applyTo(*doc); std::unique_ptr<ArrayFieldValue> fval2(doc->getAs<ArrayFieldValue>(doc->getField("tags"))); @@ -270,15 +270,15 @@ TEST(DocumentUpdateTest, testUpdateArray) ASSERT_THROW( DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(FieldUpdate(doc->getField("tags")) - .addUpdate(std::make_unique<AssignValueUpdate>(std::make_unique<StringFieldValue>("THROW MEH!")))) + .addUpdate(std::make_unique<AssignValueUpdate>(StringFieldValue::make("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::make_unique<RemoveValueUpdate>(std::make_unique<StringFieldValue>("foo"))) - .addUpdate(std::make_unique<RemoveValueUpdate>(std::make_unique<StringFieldValue>("tag")))) + .addUpdate(std::make_unique<RemoveValueUpdate>(StringFieldValue::make("foo"))) + .addUpdate(std::make_unique<RemoveValueUpdate>(StringFieldValue::make("tag")))) .applyTo(*doc); auto fval3(doc->getAs<ArrayFieldValue>(doc->getField("tags"))); ASSERT_EQ((size_t) 2, fval3->size()); @@ -299,7 +299,7 @@ TEST(DocumentUpdateTest, testUpdateArray) std::unique_ptr<ValueUpdate> createAddUpdate(vespalib::stringref key, int weight) { - auto upd = std::make_unique<AddValueUpdate>(std::make_unique<StringFieldValue>(key)); + auto upd = std::make_unique<AddValueUpdate>(StringFieldValue::make(key)); upd->setWeight(weight); return upd; } @@ -371,8 +371,8 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) // Remove weighted field DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(FieldUpdate(field) - .addUpdate(std::make_unique<RemoveValueUpdate>(std::make_unique<StringFieldValue>("foo"))) - .addUpdate(std::make_unique<RemoveValueUpdate>(std::make_unique<StringFieldValue>("too")))) + .addUpdate(std::make_unique<RemoveValueUpdate>(StringFieldValue::make("foo"))) + .addUpdate(std::make_unique<RemoveValueUpdate>(StringFieldValue::make("too")))) .applyTo(*doc); auto fval4(doc->getAs<WeightedSetFieldValue>(field)); ASSERT_EQ((size_t) 1, fval4->size()); @@ -419,7 +419,7 @@ WeightedSetAutoCreateFixture::WeightedSetAutoCreateFixture() update(repo, *docType, DocumentId("id:ns:test::1")) { update.addUpdate(FieldUpdate(field) - .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<StringFieldValue>("foo"), + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue::make("foo"), std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 1)))); } } // anon ns @@ -457,7 +457,7 @@ TEST(DocumentUpdateTest, testIncrementWithZeroResultWeightIsRemoved) { WeightedSetAutoCreateFixture fixture; fixture.update.addUpdate(FieldUpdate(fixture.field) - .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<StringFieldValue>("baz"), + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue::make("baz"), std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 0)))); fixture.applyUpdateToDocument(); @@ -549,9 +549,9 @@ TEST(DocumentUpdateTest, testGenerateSerializedFile) upd.addUpdate(FieldUpdate(type->getField("intfield")) .addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 3))); upd.addUpdate(FieldUpdate(type->getField("wsfield")) - .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<StringFieldValue>("foo"), + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue::make("foo"), std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 2))) - .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<StringFieldValue>("foo"), + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue::make("foo"), std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Mul, 2)))); nbostream buf(serializeHEAD(upd)); writeBufferToFile(buf, "data/serializeupdatecpp.dat"); @@ -732,7 +732,7 @@ TEST(DocumentUpdateTest, testMapValueUpdate) DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(FieldUpdate(field1) - .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<StringFieldValue>("banana"), + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue::make("banana"), std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 1.0)))) .applyTo(*doc); std::unique_ptr<WeightedSetFieldValue> fv1 = @@ -741,7 +741,7 @@ TEST(DocumentUpdateTest, testMapValueUpdate) DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(FieldUpdate(field2) - .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<StringFieldValue>("banana"), + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue::make("banana"), std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 1.0)))) .applyTo(*doc); auto fv2 = doc->getAs<WeightedSetFieldValue>(field2); @@ -770,7 +770,7 @@ TEST(DocumentUpdateTest, testMapValueUpdate) DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(FieldUpdate(field1) - .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<StringFieldValue>("apple"), + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue::make("apple"), std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Sub, 1.0)))) .applyTo(*doc); @@ -780,7 +780,7 @@ TEST(DocumentUpdateTest, testMapValueUpdate) DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(FieldUpdate(field2) - .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<StringFieldValue>("apple"), + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue::make("apple"), std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Sub, 1.0)))) .applyTo(*doc); @@ -1282,7 +1282,7 @@ ArrayUpdateFixture::ArrayUpdateFixture() update = std::make_unique<DocumentUpdate>(doc_man.getTypeRepo(), *doc->getDataType(), doc->getId()); update->addUpdate(FieldUpdate(array_field) .addUpdate(std::make_unique<MapValueUpdate>(std::make_unique<IntFieldValue>(1), - std::make_unique<AssignValueUpdate>(std::make_unique<StringFieldValue>("bar"))))); + std::make_unique<AssignValueUpdate>(StringFieldValue::make("bar"))))); } ArrayUpdateFixture::~ArrayUpdateFixture() = default; diff --git a/document/src/tests/feed_reject_helper_test.cpp b/document/src/tests/feed_reject_helper_test.cpp index 278e89b15a3..fd217601b6c 100644 --- a/document/src/tests/feed_reject_helper_test.cpp +++ b/document/src/tests/feed_reject_helper_test.cpp @@ -53,7 +53,7 @@ TEST(DocumentRejectTest, requireThatFixedSizeFieldValuesAreDetected) { TEST(DocumentRejectTest, requireThatClearRemoveTensorRemoveAndArtithmeticUpdatesIgnoreFeedRejection) { EXPECT_FALSE(FeedRejectHelper::mustReject(ClearValueUpdate())); - EXPECT_FALSE(FeedRejectHelper::mustReject(RemoveValueUpdate(std::make_unique<StringFieldValue>()))); + EXPECT_FALSE(FeedRejectHelper::mustReject(RemoveValueUpdate(StringFieldValue::make()))); EXPECT_FALSE(FeedRejectHelper::mustReject(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 5.0))); EXPECT_FALSE(FeedRejectHelper::mustReject(TensorRemoveUpdate(std::make_unique<TensorFieldValue>()))); } @@ -68,7 +68,7 @@ TEST(DocumentRejectTest, requireThatAddMapTensorModifyAndTensorAddUpdatesWillBeR TEST(DocumentRejectTest, requireThatAssignUpdatesWillBeRejectedBasedOnTheirContent) { EXPECT_FALSE(FeedRejectHelper::mustReject(AssignValueUpdate(std::make_unique<IntFieldValue>()))); - EXPECT_TRUE(FeedRejectHelper::mustReject(AssignValueUpdate(std::make_unique<StringFieldValue>()))); + EXPECT_TRUE(FeedRejectHelper::mustReject(AssignValueUpdate(StringFieldValue::make()))); } } diff --git a/document/src/tests/testxml.cpp b/document/src/tests/testxml.cpp index 998d41480f3..5f194661fe5 100644 --- a/document/src/tests/testxml.cpp +++ b/document/src/tests/testxml.cpp @@ -62,7 +62,7 @@ createTestDocumentUpdate(const DocumentTypeRepo& repo) up->addUpdate(FieldUpdate(type->getField("intattr")) .addUpdate(std::make_unique<AssignValueUpdate>(std::make_unique<IntFieldValue>(7)))); up->addUpdate(FieldUpdate(type->getField("stringattr")) - .addUpdate(std::make_unique<AssignValueUpdate>(std::make_unique<StringFieldValue>("New value")))); + .addUpdate(std::make_unique<AssignValueUpdate>(StringFieldValue::make("New value")))); up->addUpdate(FieldUpdate(type->getField("arrayattr")) .addUpdate(std::make_unique<AddValueUpdate>(std::make_unique<IntFieldValue>(123))) .addUpdate(std::make_unique<AddValueUpdate>(std::make_unique<IntFieldValue>(456)))); diff --git a/document/src/vespa/document/update/assignvalueupdate.h b/document/src/vespa/document/update/assignvalueupdate.h index 1e006d3baed..071dcc2236d 100644 --- a/document/src/vespa/document/update/assignvalueupdate.h +++ b/document/src/vespa/document/update/assignvalueupdate.h @@ -22,7 +22,7 @@ class AssignValueUpdate final : public ValueUpdate { ACCEPT_UPDATE_VISITOR; public: AssignValueUpdate(); - AssignValueUpdate(std::unique_ptr<FieldValue> value); + explicit AssignValueUpdate(std::unique_ptr<FieldValue> value); AssignValueUpdate(const AssignValueUpdate& value) = delete; AssignValueUpdate & operator=(const AssignValueUpdate& value) = delete; ~AssignValueUpdate() override; diff --git a/document/src/vespa/document/update/removevalueupdate.h b/document/src/vespa/document/update/removevalueupdate.h index cfce9b5234a..02f8204de23 100644 --- a/document/src/vespa/document/update/removevalueupdate.h +++ b/document/src/vespa/document/update/removevalueupdate.h @@ -22,7 +22,7 @@ public: * * @param value The identifier of the field value to update. */ - RemoveValueUpdate(std::unique_ptr<FieldValue> key); + explicit RemoveValueUpdate(std::unique_ptr<FieldValue> key); RemoveValueUpdate(const RemoveValueUpdate &) = delete; RemoveValueUpdate & operator=(const RemoveValueUpdate &) = delete; ~RemoveValueUpdate() override; diff --git a/document/src/vespa/document/update/tensor_add_update.cpp b/document/src/vespa/document/update/tensor_add_update.cpp index b3bb4d7623d..4110a94693f 100644 --- a/document/src/vespa/document/update/tensor_add_update.cpp +++ b/document/src/vespa/document/update/tensor_add_update.cpp @@ -29,7 +29,7 @@ TensorAddUpdate::TensorAddUpdate() { } -TensorAddUpdate::TensorAddUpdate(std::unique_ptr<TensorFieldValue> &&tensor) +TensorAddUpdate::TensorAddUpdate(std::unique_ptr<TensorFieldValue> tensor) : ValueUpdate(TensorAdd), TensorUpdate(), _tensor(std::move(tensor)) diff --git a/document/src/vespa/document/update/tensor_add_update.h b/document/src/vespa/document/update/tensor_add_update.h index 00346b4e723..20e231b4294 100644 --- a/document/src/vespa/document/update/tensor_add_update.h +++ b/document/src/vespa/document/update/tensor_add_update.h @@ -21,7 +21,7 @@ class TensorAddUpdate final : public ValueUpdate, public TensorUpdate { TensorAddUpdate(); ACCEPT_UPDATE_VISITOR; public: - TensorAddUpdate(std::unique_ptr<TensorFieldValue> &&tensor); + explicit TensorAddUpdate(std::unique_ptr<TensorFieldValue> tensor); TensorAddUpdate(const TensorAddUpdate &rhs) = delete; TensorAddUpdate &operator=(const TensorAddUpdate &rhs) = delete; ~TensorAddUpdate() override; diff --git a/document/src/vespa/document/update/tensor_remove_update.cpp b/document/src/vespa/document/update/tensor_remove_update.cpp index 74c0cbe6c63..25af29ce6b8 100644 --- a/document/src/vespa/document/update/tensor_remove_update.cpp +++ b/document/src/vespa/document/update/tensor_remove_update.cpp @@ -50,9 +50,8 @@ TensorRemoveUpdate::TensorRemoveUpdate(std::unique_ptr<TensorFieldValue> tensor) : ValueUpdate(TensorRemove), TensorUpdate(), _tensorType(std::make_unique<TensorDataType>(dynamic_cast<const TensorDataType &>(*tensor->getDataType()))), - _tensor(static_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) + _tensor(std::move(tensor)) { - *_tensor = *tensor; } TensorRemoveUpdate::~TensorRemoveUpdate() = default; diff --git a/document/src/vespa/document/update/tensor_remove_update.h b/document/src/vespa/document/update/tensor_remove_update.h index 06b0c512b4b..ca908fc75fc 100644 --- a/document/src/vespa/document/update/tensor_remove_update.h +++ b/document/src/vespa/document/update/tensor_remove_update.h @@ -26,7 +26,7 @@ private: ACCEPT_UPDATE_VISITOR; public: - TensorRemoveUpdate(std::unique_ptr<TensorFieldValue> tensor); + explicit TensorRemoveUpdate(std::unique_ptr<TensorFieldValue> tensor); TensorRemoveUpdate(const TensorRemoveUpdate &rhs) = delete; TensorRemoveUpdate &operator=(const TensorRemoveUpdate &rhs) = delete; ~TensorRemoveUpdate() override; diff --git a/document/src/vespa/document/update/valueupdate.cpp b/document/src/vespa/document/update/valueupdate.cpp index 4af61178a79..50866311518 100644 --- a/document/src/vespa/document/update/valueupdate.cpp +++ b/document/src/vespa/document/update/valueupdate.cpp @@ -36,8 +36,9 @@ ValueUpdate::className() const noexcept { return "TensorModifyUpdate"; case TensorRemove: return "TensorRemoveUpdate"; + default: + abort(); } - abort(); } std::unique_ptr<ValueUpdate> @@ -61,8 +62,9 @@ ValueUpdate::create(ValueUpdateType type) { return std::unique_ptr<TensorModifyUpdate>( new TensorModifyUpdate()); case TensorRemove: return std::unique_ptr<TensorRemoveUpdate>( new TensorRemoveUpdate()); + default: + throw std::runtime_error(vespalib::make_string("Could not find a class for classId %d(%x)", type, type)); } - throw std::runtime_error(vespalib::make_string("Could not find a class for classId %d(%x)", type, type)); } std::unique_ptr<ValueUpdate> |