summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-08-29 11:38:34 +0200
committerTor Egge <Tor.Egge@online.no>2022-08-29 11:38:34 +0200
commitbfeb39f0ad4a6b2c2b1d09757507c42ef78a1c60 (patch)
treea25a8936794a6c98c00eeabb7b669d97cfeec080
parentee29a7aeb10021c55064f6c5268daefe23897f0d (diff)
Reduce use of new in summary field converter unit test.
-rw-r--r--document/src/vespa/document/annotation/spantree.cpp16
-rw-r--r--document/src/vespa/document/annotation/spantree.h8
-rw-r--r--searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp2
-rw-r--r--searchsummary/src/tests/docsummary/positionsdfw_test.cpp2
-rw-r--r--searchsummary/src/tests/docsummary/summary_field_converter/summary_field_converter_test.cpp49
5 files changed, 42 insertions, 35 deletions
diff --git a/document/src/vespa/document/annotation/spantree.cpp b/document/src/vespa/document/annotation/spantree.cpp
index d483d6c08ca..65cccc97b26 100644
--- a/document/src/vespa/document/annotation/spantree.cpp
+++ b/document/src/vespa/document/annotation/spantree.cpp
@@ -12,20 +12,32 @@ namespace document {
SpanTree::~SpanTree() = default;
size_t
+SpanTree::annotate(Annotation&& annotation_) {
+ _annotations.push_back(std::move(annotation_));
+ return _annotations.size() - 1;
+}
+
+size_t
SpanTree::annotate(std::unique_ptr<Annotation> annotation_) {
_annotations.push_back(std::move(*annotation_));
return _annotations.size() - 1;
}
size_t
+SpanTree::annotate(const SpanNode &node, Annotation&& annotation_) {
+ annotation_.setSpanNode(node);
+ return annotate(std::move(annotation_));
+}
+
+size_t
SpanTree::annotate(const SpanNode &node, std::unique_ptr<Annotation> annotation_) {
annotation_->setSpanNode(node);
return annotate(std::move(annotation_));
}
size_t
-SpanTree::annotate(const SpanNode &node, const AnnotationType &type) {
- return annotate(node, std::make_unique<Annotation>(type));
+SpanTree::annotate(const SpanNode &node, const AnnotationType &annotation_type) {
+ return annotate(node, Annotation(annotation_type));
}
void
diff --git a/document/src/vespa/document/annotation/spantree.h b/document/src/vespa/document/annotation/spantree.h
index 7635350025b..c427c9ec7bd 100644
--- a/document/src/vespa/document/annotation/spantree.h
+++ b/document/src/vespa/document/annotation/spantree.h
@@ -29,9 +29,11 @@ public:
~SpanTree();
// The annotate functions return the annotation index.
- size_t annotate(std::unique_ptr<Annotation> annotation);
- size_t annotate(const SpanNode &node, std::unique_ptr<Annotation> a);
- size_t annotate(const SpanNode &node, const AnnotationType &a_type);
+ size_t annotate(Annotation&& annotation_);
+ size_t annotate(std::unique_ptr<Annotation> annotation_);
+ size_t annotate(const SpanNode& node, Annotation&& annotation_);
+ size_t annotate(const SpanNode& node, std::unique_ptr<Annotation> annotation_);
+ size_t annotate(const SpanNode& node, const AnnotationType& annotation_type);
Annotation & annotation(size_t index) { return _annotations[index]; }
const Annotation & annotation(size_t index) const { return _annotations[index]; }
diff --git a/searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp b/searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp
index 9143f17cb67..06a20563161 100644
--- a/searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp
+++ b/searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp
@@ -44,7 +44,7 @@ make_doc_type_repo()
DocumenttypesConfigBuilderHelper builder;
builder.document(doc_type_id, doc_type_name,
Struct(header_name), Struct(body_name));
- return std::unique_ptr<const DocumentTypeRepo>(new DocumentTypeRepo(builder.config()));
+ return std::make_unique<const DocumentTypeRepo>(builder.config());
}
class DocumentIdDFWTest : public ::testing::Test
diff --git a/searchsummary/src/tests/docsummary/positionsdfw_test.cpp b/searchsummary/src/tests/docsummary/positionsdfw_test.cpp
index 60584b26e31..09051e2e9c0 100644
--- a/searchsummary/src/tests/docsummary/positionsdfw_test.cpp
+++ b/searchsummary/src/tests/docsummary/positionsdfw_test.cpp
@@ -98,7 +98,7 @@ public:
}
IAttributeContext::UP createContext() const override {
- return IAttributeContext::UP(new MyAttributeContext(_attr));
+ return std::make_unique<MyAttributeContext>(_attr);
}
std::shared_ptr<attribute::ReadableAttributeVector> readable_attribute_vector(const string&) const override {
diff --git a/searchsummary/src/tests/docsummary/summary_field_converter/summary_field_converter_test.cpp b/searchsummary/src/tests/docsummary/summary_field_converter/summary_field_converter_test.cpp
index 06766ba370a..c6f310f2d53 100644
--- a/searchsummary/src/tests/docsummary/summary_field_converter/summary_field_converter_test.cpp
+++ b/searchsummary/src/tests/docsummary/summary_field_converter/summary_field_converter_test.cpp
@@ -242,7 +242,7 @@ DocumenttypesConfig getDocumenttypesConfig() {
}
Test::Test() :
- _documentRepo(new DocumentTypeRepo(getDocumenttypesConfig())),
+ _documentRepo(std::make_unique<DocumentTypeRepo>(getDocumenttypesConfig())),
_documentType(_documentRepo->getDocumentType("indexingdocument")),
_fixedRepo(*_documentRepo, *_documentType)
{
@@ -285,8 +285,8 @@ Test::Main()
}
void Test::setUp() {
- _schema.reset(new Schema);
- _summarymap.reset(new SummarymapConfigBuilder);
+ _schema = std::make_unique<Schema>();
+ _summarymap = std::make_unique<SummarymapConfigBuilder>();
}
void Test::tearDown() {
@@ -298,34 +298,26 @@ const DataType &Test::getDataType(const string &name) const {
return *type;
}
-template <typename T>
-std::unique_ptr<T> makeUP(T *p) { return std::unique_ptr<T>(p); }
-
StringFieldValue Test::makeAnnotatedString() {
- SpanList *span_list = new SpanList;
- SpanTree::UP tree(new SpanTree(SPANTREE_NAME, makeUP(span_list)));
+ auto span_list_up = std::make_unique<SpanList>();
+ auto span_list = span_list_up.get();
+ auto tree = std::make_unique<SpanTree>(SPANTREE_NAME, std::move(span_list_up));
// Annotations don't have to be added sequentially.
- tree->annotate(span_list->add(makeUP(new Span(8, 3))),
- makeUP(new Annotation(*TERM,
- makeUP(new StringFieldValue(
- "Annotation")))));
- tree->annotate(span_list->add(makeUP(new Span(0, 3))), *TERM);
- tree->annotate(span_list->add(makeUP(new Span(4, 3))), *TERM);
- tree->annotate(span_list->add(makeUP(new Span(4, 3))),
- makeUP(new Annotation(*TERM,
- makeUP(new StringFieldValue(
- "Multiple")))));
- tree->annotate(span_list->add(makeUP(new Span(1, 2))),
- makeUP(new Annotation(*TERM,
- makeUP(new StringFieldValue(
- "Overlap")))));
+ tree->annotate(span_list->add(std::make_unique<Span>(8, 3)),
+ Annotation(*TERM, std::make_unique<StringFieldValue>("Annotation")));
+ tree->annotate(span_list->add(std::make_unique<Span>(0, 3)), *TERM);
+ tree->annotate(span_list->add(std::make_unique<Span>(4, 3)), *TERM);
+ tree->annotate(span_list->add(std::make_unique<Span>(4, 3)),
+ Annotation(*TERM, std::make_unique<StringFieldValue>("Multiple")));
+ tree->annotate(span_list->add(std::make_unique<Span>(1, 2)),
+ Annotation(*TERM, std::make_unique<StringFieldValue>("Overlap")));
StringFieldValue value("Foo Bar Baz");
setSpanTree(value, std::move(tree));
return value;
}
StringFieldValue Test::annotateTerm(const string &term) {
- SpanTree::UP tree(new SpanTree(SPANTREE_NAME, makeUP(new Span(0, term.size()))));
+ auto tree = std::make_unique<SpanTree>(SPANTREE_NAME, std::make_unique<Span>(0, term.size()));
tree->annotate(tree->getRoot(), *TERM);
StringFieldValue value(term);
setSpanTree(value, std::move(tree));
@@ -339,11 +331,12 @@ void Test::setSpanTree(StringFieldValue & value, SpanTree::UP tree) {
}
StringFieldValue Test::makeAnnotatedChineseString() {
- SpanList *span_list = new SpanList;
- SpanTree::UP tree(new SpanTree(SPANTREE_NAME, makeUP(span_list)));
+ auto span_list_up = std::make_unique<SpanList>();
+ auto span_list = span_list_up.get();
+ auto tree = std::make_unique<SpanTree>(SPANTREE_NAME, std::move(span_list_up));
// These chinese characters each use 3 bytes in their UTF8 encoding.
- tree->annotate(span_list->add(makeUP(new Span(0, 15))), *TERM);
- tree->annotate(span_list->add(makeUP(new Span(15, 9))), *TERM);
+ tree->annotate(span_list->add(std::make_unique<Span>(0, 15)), *TERM);
+ tree->annotate(span_list->add(std::make_unique<Span>(15, 9)), *TERM);
StringFieldValue value("我就是那个大灰狼");
setSpanTree(value, std::move(tree));
return value;
@@ -660,7 +653,7 @@ void Test::requireThatLinguisticsAnnotationUsesDefaultDataTypes() {
void
Test::requireThatPredicateIsPrinted()
{
- std::unique_ptr<Slime> input(new Slime());
+ auto input = std::make_unique<Slime>();
Cursor &obj = input->setObject();
obj.setLong(Predicate::NODE_TYPE, Predicate::TYPE_FEATURE_SET);
obj.setString(Predicate::KEY, "foo");