From 77a4c434005430aa69146375b576f52294bfe742 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 3 Sep 2019 05:24:00 +0000 Subject: std::make_unique and c++11 for loops. --- .../proton/matching/blueprintbuilder.cpp | 5 ++--- .../queryeval/create_blueprint_visitor_helper.cpp | 23 +++++++++------------- .../queryeval/create_blueprint_visitor_helper.h | 7 ++----- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp index 672e7f78784..656e49d7569 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp @@ -103,9 +103,8 @@ private: void buildSameElement(ProtonSameElement &n) { SameElementBuilder builder(_requestContext, _context); - for (size_t i = 0; i < n.getChildren().size(); ++i) { - search::query::Node &node = *n.getChildren()[i]; - builder.add_child(node); + for (search::query::Node *node : n.getChildren()) { + builder.add_child(*node); } _result = builder.build(); } diff --git a/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp b/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp index 5cd74229fce..e3588d88ccb 100644 --- a/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp @@ -32,10 +32,10 @@ CreateBlueprintVisitorHelper::getResult() void CreateBlueprintVisitorHelper::visitPhrase(query::Phrase &n) { auto phrase = std::make_unique(_field, _requestContext); - for (size_t i = 0; i < n.getChildren().size(); ++i) { + for (const query::Node * child : n.getChildren()) { FieldSpecList fields; fields.add(phrase->getNextChildField(_field)); - phrase->addTerm(_searchable.createBlueprint(_requestContext, fields, *n.getChildren()[i])); + phrase->addTerm(_searchable.createBlueprint(_requestContext, fields, *child)); } setResult(std::move(phrase)); } @@ -64,8 +64,7 @@ CreateBlueprintVisitorHelper::handleNumberTermAsText(query::NumberTerm &n) template void -CreateBlueprintVisitorHelper::createWeightedSet(WS *bp, NODE &n) { - Blueprint::UP result(bp); +CreateBlueprintVisitorHelper::createWeightedSet(std::unique_ptr bp, NODE &n) { FieldSpecList fields; for (size_t i = 0; i < n.getChildren().size(); ++i) { fields.clear(); @@ -74,25 +73,21 @@ CreateBlueprintVisitorHelper::createWeightedSet(WS *bp, NODE &n) { uint32_t weight = getWeightFromNode(node).percent(); bp->addTerm(_searchable.createBlueprint(_requestContext, fields, node), weight); } - setResult(std::move(result)); + setResult(std::move(bp)); } void CreateBlueprintVisitorHelper::visitWeightedSetTerm(query::WeightedSetTerm &n) { - WeightedSetTermBlueprint *bp = new WeightedSetTermBlueprint(_field); - createWeightedSet(bp, n); + createWeightedSet(std::make_unique(_field), n); } void CreateBlueprintVisitorHelper::visitDotProduct(query::DotProduct &n) { - DotProductBlueprint *bp = new DotProductBlueprint(_field); - createWeightedSet(bp, n); + createWeightedSet(std::make_unique(_field), n); } void CreateBlueprintVisitorHelper::visitWandTerm(query::WandTerm &n) { - ParallelWeakAndBlueprint *bp = new ParallelWeakAndBlueprint(_field, - n.getTargetNumHits(), - n.getScoreThreshold(), - n.getThresholdBoostFactor()); - createWeightedSet(bp, n); + createWeightedSet(std::make_unique(_field, n.getTargetNumHits(), + n.getScoreThreshold(), n.getThresholdBoostFactor()), + n); } } diff --git a/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.h b/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.h index 5bcc4f4c4c5..84830111fde 100644 --- a/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.h +++ b/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.h @@ -25,10 +25,7 @@ protected: public: CreateBlueprintVisitorHelper(Searchable &searchable, const FieldSpec &field, const IRequestContext & requestContext); - ~CreateBlueprintVisitorHelper(); - - template - std::unique_ptr make_UP(T *p) { return std::unique_ptr(p); } + ~CreateBlueprintVisitorHelper() override; template void setResult(std::unique_ptr result) { _result = std::move(result); } @@ -40,7 +37,7 @@ public: void visitPhrase(query::Phrase &n); template - void createWeightedSet(WS *bp, NODE &n); + void createWeightedSet(std::unique_ptr bp, NODE &n); void visitWeightedSetTerm(query::WeightedSetTerm &n); void visitDotProduct(query::DotProduct &n); void visitWandTerm(query::WandTerm &n); -- cgit v1.2.3