diff options
8 files changed, 40 insertions, 62 deletions
diff --git a/document/src/tests/annotation/annotation_test.cpp b/document/src/tests/annotation/annotation_test.cpp index 2700cfcf96f..b18fa113d9b 100644 --- a/document/src/tests/annotation/annotation_test.cpp +++ b/document/src/tests/annotation/annotation_test.cpp @@ -156,8 +156,8 @@ TEST("requireThatAnnotationsCanHaveValues") { TEST("requireThatAnnotationsCanReferenceAnnotations") { auto root = std::make_unique<SpanList>(); SpanTree tree("html", std::move(root)); - size_t san_index = tree.annotate(makeUP(new Annotation(text_type))); - size_t fran_index = tree.annotate(makeUP(new Annotation(text_type))); + size_t san_index = tree.annotate(Annotation(text_type)); + size_t fran_index = tree.annotate(Annotation(text_type)); AnnotationReferenceDataType annotation_ref_type(text_type, 101); ArrayDataType array_type(annotation_ref_type); diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp index 40d78327ab4..7528878bfb5 100644 --- a/document/src/tests/serialization/vespadocumentserializer_test.cpp +++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp @@ -626,7 +626,7 @@ TEST("requireThatDocumentWithDocumentCanBeSerialized") { const AnnotationType *a_type =my_repo.getAnnotationType(*inner_type, a_id); StringFieldValue str("foo"); auto tree = std::make_unique<SpanTree>("name", std::make_unique<Span>(0, 3)); - tree->annotate(std::make_unique<Annotation>(*a_type)); + tree->annotate(Annotation(*a_type)); setSpanTree(str, *tree); diff --git a/document/src/vespa/document/annotation/spantree.cpp b/document/src/vespa/document/annotation/spantree.cpp index d483d6c08ca..4d24b4ce788 100644 --- a/document/src/vespa/document/annotation/spantree.cpp +++ b/document/src/vespa/document/annotation/spantree.cpp @@ -12,20 +12,20 @@ namespace document { SpanTree::~SpanTree() = default; size_t -SpanTree::annotate(std::unique_ptr<Annotation> annotation_) { - _annotations.push_back(std::move(*annotation_)); +SpanTree::annotate(Annotation&& annotation_) { + _annotations.push_back(std::move(annotation_)); return _annotations.size() - 1; } size_t -SpanTree::annotate(const SpanNode &node, std::unique_ptr<Annotation> annotation_) { - annotation_->setSpanNode(node); +SpanTree::annotate(const SpanNode &node, 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..03ee820466c 100644 --- a/document/src/vespa/document/annotation/spantree.h +++ b/document/src/vespa/document/annotation/spantree.h @@ -29,9 +29,9 @@ 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(const SpanNode& node, 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/searchlib/src/vespa/searchlib/index/docbuilder.cpp b/searchlib/src/vespa/searchlib/index/docbuilder.cpp index d4bf9e86c74..bf0a6866a1a 100644 --- a/searchlib/src/vespa/searchlib/index/docbuilder.cpp +++ b/searchlib/src/vespa/searchlib/index/docbuilder.cpp @@ -111,21 +111,6 @@ insertRaw(const Schema::Field & sfield, rfvalue->setValue(static_cast<const char *>(buf), len); } - -template <typename T> -std::unique_ptr<T> -make_UP(T *p) -{ - return std::unique_ptr<T>(p); -} - -template <typename T> -std::unique_ptr<T> -makeUP(T *p) -{ - return std::unique_ptr<T>(p); -} - } namespace docbuilderkludge @@ -154,10 +139,10 @@ using namespace docbuilderkludge; namespace { -std::unique_ptr<Annotation> +Annotation makeTokenType(linguistics::TokenType type) { - return std::make_unique<Annotation>(*AnnotationType::TOKEN_TYPE, std::make_unique<IntFieldValue>(type)); + return Annotation(*AnnotationType::TOKEN_TYPE, std::make_unique<IntFieldValue>(type)); } } @@ -337,7 +322,7 @@ DocBuilder::IndexFieldHandle::addTokenizedString(const vespalib::string &val, void DocBuilder::IndexFieldHandle::addSpan(size_t start, size_t len) { - const SpanNode &span = _spanList->add(makeUP(new Span(start, len))); + const SpanNode &span = _spanList->add(std::make_unique<Span>(start, len)); _lastSpan = &span; } @@ -388,8 +373,8 @@ DocBuilder::IndexFieldHandle::addTermAnnotation(const vespalib::string &val) assert(_spanTree); assert(_lastSpan != nullptr); _spanTree->annotate(*_lastSpan, - makeUP(new Annotation(*AnnotationType::TERM, - makeUP(new StringFieldValue(val))))); + Annotation(*AnnotationType::TERM, + std::make_unique<StringFieldValue>(val))); } void 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"); |