diff options
author | HÃ¥vard Pettersen <3535158+havardpe@users.noreply.github.com> | 2019-09-03 12:04:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-03 12:04:02 +0200 |
commit | c8cddf4d1e98ad95a0659769f956fcbb85c5259c (patch) | |
tree | f9e94226008e854a643215c3ef487b9f23af3b8a | |
parent | 5e7853aeb652d1be4a6b3891463e0b986f7b7969 (diff) | |
parent | 77a4c434005430aa69146375b576f52294bfe742 (diff) |
Merge pull request #10495 from vespa-engine/balder/modernize-13
std::make_unique and c++11 for loops.
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<SimplePhraseBlueprint>(_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 <typename WS, typename NODE> void -CreateBlueprintVisitorHelper::createWeightedSet(WS *bp, NODE &n) { - Blueprint::UP result(bp); +CreateBlueprintVisitorHelper::createWeightedSet(std::unique_ptr<WS> 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<WeightedSetTermBlueprint>(_field), n); } void CreateBlueprintVisitorHelper::visitDotProduct(query::DotProduct &n) { - DotProductBlueprint *bp = new DotProductBlueprint(_field); - createWeightedSet(bp, n); + createWeightedSet(std::make_unique<DotProductBlueprint>(_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<ParallelWeakAndBlueprint>(_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 <typename T> - std::unique_ptr<T> make_UP(T *p) { return std::unique_ptr<T>(p); } + ~CreateBlueprintVisitorHelper() override; template <typename T> void setResult(std::unique_ptr<T> result) { _result = std::move(result); } @@ -40,7 +37,7 @@ public: void visitPhrase(query::Phrase &n); template <typename WS, typename NODE> - void createWeightedSet(WS *bp, NODE &n); + void createWeightedSet(std::unique_ptr<WS> bp, NODE &n); void visitWeightedSetTerm(query::WeightedSetTerm &n); void visitDotProduct(query::DotProduct &n); void visitWandTerm(query::WandTerm &n); |