diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-16 13:54:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-16 13:54:32 +0100 |
commit | 9b977d6fb3be325055c5e7f0ae0f58267fc67e2c (patch) | |
tree | 5bf75e18a9af70ca5b0af22b4d3e82e5ba97e61b /searchlib | |
parent | 9dc1c4fd4e421663d34715ad045355746325745a (diff) | |
parent | 838d604c77978c6be24740a3abdb1aba22929337 (diff) |
Merge pull request #29343 from vespa-engine/balder/minor-cleanup
Simplify and follow advice from clion while reading code.
Diffstat (limited to 'searchlib')
6 files changed, 131 insertions, 163 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp index 1d908bed568..372b76fa9af 100644 --- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp @@ -81,7 +81,7 @@ public: } FieldSpecBaseList exposeFields() const override { - return FieldSpecBaseList(); + return {}; } bool inheritStrict(size_t i) const override { @@ -140,7 +140,7 @@ struct MyTerm : SimpleLeafBlueprint { setEstimate(HitEstimate(hitEstimate, false)); } SearchIterator::UP createLeafSearch(const search::fef::TermFieldMatchDataArray &, bool) const override { - return SearchIterator::UP(); + return {}; } SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { return create_default_filter(strict, constraint); @@ -311,13 +311,13 @@ TEST("testHitEstimateCalculation") TEST("testHitEstimatePropagation") { - MyLeaf *leaf1 = new MyLeaf(); + auto *leaf1 = new MyLeaf(); leaf1->estimate(10); - MyLeaf *leaf2 = new MyLeaf(); + auto *leaf2 = new MyLeaf(); leaf2->estimate(20); - MyLeaf *leaf3 = new MyLeaf(); + auto *leaf3 = new MyLeaf(); leaf3->estimate(30); MyOr *parent = new MyOr(); @@ -346,7 +346,7 @@ TEST("testHitEstimatePropagation") leaf3->estimate(25); EXPECT_EQUAL(20u, root->getState().estimate().estHits); parent->addChild(std::move(tmp)); - EXPECT_TRUE(tmp.get() == 0); + EXPECT_FALSE(tmp); EXPECT_EQUAL(25u, root->getState().estimate().estHits); } @@ -572,7 +572,7 @@ TEST_F("testSearchCreation", Fixture) .addField(3, 3).create()); SearchIterator::UP leafsearch = f.create(*l); - MySearch *lw = new MySearch("leaf", true, true); + auto *lw = new MySearch("leaf", true, true); lw->addHandle(1).addHandle(2).addHandle(3); SearchIterator::UP wantleaf(lw); @@ -584,11 +584,11 @@ TEST_F("testSearchCreation", Fixture) .add(MyLeafSpec(2).addField(2, 2).create())); SearchIterator::UP andsearch = f.create(*a); - MySearch *l1 = new MySearch("leaf", true, true); - MySearch *l2 = new MySearch("leaf", true, false); + auto *l1 = new MySearch("leaf", true, true); + auto *l2 = new MySearch("leaf", true, false); l1->addHandle(1); l2->addHandle(2); - MySearch *aw = new MySearch("and", false, true); + auto *aw = new MySearch("and", false, true); aw->add(l1); aw->add(l2); SearchIterator::UP wanted(aw); @@ -600,11 +600,11 @@ TEST_F("testSearchCreation", Fixture) .add(MyLeafSpec(2).addField(2, 22).create())); SearchIterator::UP orsearch = f.create(*o); - MySearch *l1 = new MySearch("leaf", true, true); - MySearch *l2 = new MySearch("leaf", true, true); + auto *l1 = new MySearch("leaf", true, true); + auto *l2 = new MySearch("leaf", true, true); l1->addHandle(11); l2->addHandle(22); - MySearch *ow = new MySearch("or", false, true); + auto *ow = new MySearch("or", false, true); ow->add(l1); ow->add(l2); SearchIterator::UP wanted(ow); @@ -619,7 +619,7 @@ TEST("testBlueprintMakeNew") .add(MyLeafSpec(2).addField(2, 22).create())); orig->setSourceId(42); MyOr *myOr = dynamic_cast<MyOr*>(orig.get()); - ASSERT_TRUE(myOr != 0); + ASSERT_TRUE(myOr != nullptr); EXPECT_EQUAL(42u, orig->getSourceId()); EXPECT_EQUAL(2u, orig->getState().numFields()); } diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp index db68625840c..b150f8db7c5 100644 --- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp @@ -8,7 +8,6 @@ #include <vespa/searchlib/queryeval/leaf_blueprints.h> #include <vespa/searchlib/queryeval/equiv_blueprint.h> #include <vespa/searchlib/queryeval/multisearch.h> -#include <vespa/searchlib/queryeval/andnotsearch.h> #include <vespa/searchlib/queryeval/wand/weak_and_search.h> #include <vespa/searchlib/queryeval/fake_requestcontext.h> #include <vespa/searchlib/test/diskindex/testdiskindex.h> @@ -74,13 +73,13 @@ TEST("test AndNot Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); } @@ -125,7 +124,7 @@ TEST("test And propagates updated histestimate") { bp.fetchPostings(ExecuteInfo::TRUE); EXPECT_EQUAL(3u, bp.childCnt()); for (uint32_t i = 0; i < bp.childCnt(); i++) { - const RememberExecuteInfo & child = dynamic_cast<const RememberExecuteInfo &>(bp.getChild(i)); + const auto & child = dynamic_cast<const RememberExecuteInfo &>(bp.getChild(i)); EXPECT_EQUAL((i == 0), child.executeInfo.isStrict()); } EXPECT_EQUAL(1.0f, dynamic_cast<const RememberExecuteInfo &>(bp.getChild(0)).executeInfo.hitRate()); @@ -160,16 +159,16 @@ TEST("test And Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(5u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); } @@ -208,16 +207,16 @@ TEST("test Or Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); } @@ -280,16 +279,16 @@ TEST("test Near Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(5u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); } @@ -321,16 +320,16 @@ TEST("test ONear Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(5u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); } @@ -362,16 +361,16 @@ TEST("test Rank Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); } @@ -412,16 +411,16 @@ TEST("test SourceBlender Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); } @@ -474,60 +473,60 @@ TEST("test SourceBlender below AND optimization") { auto selector_1 = std::make_unique<InvalidSelector>(); // the one auto selector_2 = std::make_unique<InvalidSelector>(); // not the one //------------------------------------------------------------------------- - AndBlueprint *top = new AndBlueprint(); + auto *top = new AndBlueprint(); Blueprint::UP top_bp(top); top->addChild(ap(MyLeafSpec(2).create())); top->addChild(ap(MyLeafSpec(1).create())); top->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); top->addChild(ap(blender)); } //------------------------------------------------------------------------- - AndBlueprint *expect = new AndBlueprint(); + auto *expect = new AndBlueprint(); Blueprint::UP expect_bp(expect); expect->addChild(ap(MyLeafSpec(1).create())); expect->addChild(ap(MyLeafSpec(2).create())); expect->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender(new SourceBlenderBlueprint(*selector_1)); + auto *blender(new SourceBlenderBlueprint(*selector_1)); { - AndBlueprint *sub_and = new AndBlueprint(); + auto *sub_and = new AndBlueprint(); sub_and->setSourceId(3); sub_and->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); sub_and->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); blender->addChild(ap(sub_and)); } { - AndBlueprint *sub_and = new AndBlueprint(); + auto *sub_and = new AndBlueprint(); sub_and->setSourceId(2); sub_and->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); sub_and->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); @@ -535,7 +534,7 @@ TEST("test SourceBlender below AND optimization") { blender->addChild(ap(sub_and)); } { - AndBlueprint *sub_and = new AndBlueprint(); + auto *sub_and = new AndBlueprint(); sub_and->setSourceId(1); sub_and->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); sub_and->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); @@ -556,51 +555,51 @@ TEST("test SourceBlender below OR optimization") { auto selector_1 = std::make_unique<InvalidSelector>(); // the one auto selector_2 = std::make_unique<InvalidSelector>(); // not the one //------------------------------------------------------------------------- - OrBlueprint *top = new OrBlueprint(); + auto *top = new OrBlueprint(); Blueprint::UP top_up(top); top->addChild(ap(MyLeafSpec(2).create())); top->addChild(ap(MyLeafSpec(1).create())); top->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); top->addChild(ap(blender)); } //------------------------------------------------------------------------- - OrBlueprint *expect = new OrBlueprint(); + auto *expect = new OrBlueprint(); Blueprint::UP expect_up(expect); { - SourceBlenderBlueprint *blender(new SourceBlenderBlueprint(*selector_1)); + auto *blender(new SourceBlenderBlueprint(*selector_1)); { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(3); sub_and->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); sub_and->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(2); sub_and->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); sub_and->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); @@ -608,7 +607,7 @@ TEST("test SourceBlender below OR optimization") { blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(1); sub_and->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); sub_and->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); @@ -618,7 +617,7 @@ TEST("test SourceBlender below OR optimization") { expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); expect->addChild(ap(blender)); @@ -638,10 +637,10 @@ TEST("test SourceBlender below AND_NOT optimization") { auto selector_1 = std::make_unique<InvalidSelector>(); // the one auto selector_2 = std::make_unique<InvalidSelector>(); // not the one //------------------------------------------------------------------------- - AndNotBlueprint *top = new AndNotBlueprint(); + auto *top = new AndNotBlueprint(); Blueprint::UP top_up(top); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(42).create()->setSourceId(1))); top->addChild(ap(blender)); } @@ -649,50 +648,50 @@ TEST("test SourceBlender below AND_NOT optimization") { top->addChild(ap(MyLeafSpec(1).create())); top->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); top->addChild(ap(blender)); } //------------------------------------------------------------------------- - AndNotBlueprint *expect = new AndNotBlueprint(); + auto *expect = new AndNotBlueprint(); Blueprint::UP expect_up(expect); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(42).create()->setSourceId(1))); expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender(new SourceBlenderBlueprint(*selector_1)); + auto *blender(new SourceBlenderBlueprint(*selector_1)); { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(3); sub_and->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); sub_and->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(2); sub_and->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); sub_and->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); @@ -700,7 +699,7 @@ TEST("test SourceBlender below AND_NOT optimization") { blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(1); sub_and->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); sub_and->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); @@ -710,7 +709,7 @@ TEST("test SourceBlender below AND_NOT optimization") { expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); expect->addChild(ap(blender)); @@ -730,10 +729,10 @@ TEST("test SourceBlender below RANK optimization") { auto selector_1 = std::make_unique<InvalidSelector>(); // the one auto selector_2 = std::make_unique<InvalidSelector>(); // not the one //------------------------------------------------------------------------- - RankBlueprint *top = new RankBlueprint(); + auto *top = new RankBlueprint(); Blueprint::UP top_up(top); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(42).create()->setSourceId(1))); top->addChild(ap(blender)); } @@ -741,36 +740,36 @@ TEST("test SourceBlender below RANK optimization") { top->addChild(ap(MyLeafSpec(1).create())); top->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); top->addChild(ap(blender)); } //------------------------------------------------------------------------- - RankBlueprint *expect = new RankBlueprint(); + auto *expect = new RankBlueprint(); Blueprint::UP expect_up(expect); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(42).create()->setSourceId(1))); expect->addChild(ap(blender)); } @@ -778,22 +777,22 @@ TEST("test SourceBlender below RANK optimization") { expect->addChild(ap(MyLeafSpec(1).create())); expect->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender(new SourceBlenderBlueprint(*selector_1)); + auto *blender(new SourceBlenderBlueprint(*selector_1)); { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(3); sub_and->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); sub_and->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(2); sub_and->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); sub_and->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); @@ -801,7 +800,7 @@ TEST("test SourceBlender below RANK optimization") { blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(1); sub_and->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); sub_and->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); @@ -847,7 +846,7 @@ TEST("test empty root node optimization and safeness") { addChild(ap(MyLeafSpec(0, true).create())). addChild(ap(MyLeafSpec(0, true).create())))); //------------------------------------------------------------------------- - Blueprint::UP expect_up(new EmptyBlueprint()); + auto expect_up = std::make_unique<EmptyBlueprint>(); //------------------------------------------------------------------------- top1_up = Blueprint::optimize(std::move(top1_up)); top2_up = Blueprint::optimize(std::move(top2_up)); @@ -872,7 +871,7 @@ TEST("and with one empty child is optimized away") { top = Blueprint::optimize(std::move(top)); Blueprint::UP expect_up(ap((new SourceBlenderBlueprint(*selector))-> addChild(ap(MyLeafSpec(10).create())). - addChild(ap(new EmptyBlueprint())))); + addChild(std::make_unique<EmptyBlueprint>()))); EXPECT_EQUAL(expect_up->asString(), top->asString()); } @@ -985,11 +984,11 @@ TEST("require that replaced blueprints retain source id") { //------------------------------------------------------------------------- // replace empty root with empty search Blueprint::UP top1_up(ap(MyLeafSpec(0, true).create()->setSourceId(13))); - Blueprint::UP expect1_up(new EmptyBlueprint()); + auto expect1_up = std::make_unique<EmptyBlueprint>(); expect1_up->setSourceId(13); //------------------------------------------------------------------------- // replace self with single child - Blueprint::UP top2_up(ap(static_cast<AndBlueprint&>((new AndBlueprint())->setSourceId(42)). + Blueprint::UP top2_up(ap(dynamic_cast<AndBlueprint&>((new AndBlueprint())->setSourceId(42)). addChild(ap(MyLeafSpec(30).create()->setSourceId(55))))); Blueprint::UP expect2_up(ap(MyLeafSpec(30).create()->setSourceId(42))); //------------------------------------------------------------------------- @@ -1038,16 +1037,16 @@ TEST("test WeakAnd Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); } @@ -1078,14 +1077,14 @@ TEST("test WeakAnd Blueprint") { { WeakAndBlueprint wa(456); MatchData::UP md = MatchData::makeTestInstance(100, 10); - wa.addTerm(Blueprint::UP(new FakeBlueprint(field, x)), 120); - wa.addTerm(Blueprint::UP(new FakeBlueprint(field, z)), 140); - wa.addTerm(Blueprint::UP(new FakeBlueprint(field, y)), 130); + wa.addTerm(std::make_unique<FakeBlueprint>(field, x), 120); + wa.addTerm(std::make_unique<FakeBlueprint>(field, z), 140); + wa.addTerm(std::make_unique<FakeBlueprint>(field, y), 130); { wa.fetchPostings(ExecuteInfo::TRUE); SearchIterator::UP search = wa.createSearch(*md, true); - EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != 0); - WeakAndSearch &s = dynamic_cast<WeakAndSearch&>(*search); + EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != nullptr); + auto &s = dynamic_cast<WeakAndSearch&>(*search); EXPECT_EQUAL(456u, s.getN()); ASSERT_EQUAL(3u, s.getTerms().size()); EXPECT_GREATER(s.get_max_score(0), 0.0); @@ -1106,7 +1105,7 @@ TEST("test WeakAnd Blueprint") { { wa.fetchPostings(ExecuteInfo::FALSE); SearchIterator::UP search = wa.createSearch(*md, false); - EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != 0); + EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != nullptr); EXPECT_TRUE(search->seek(1)); EXPECT_TRUE(search->seek(2)); EXPECT_FALSE(search->seek(3)); @@ -1216,7 +1215,7 @@ namespace { SimpleStringTerm makeTerm(const std::string & term) { - return SimpleStringTerm(term, "field", 0, search::query::Weight(0)); + return {term, "field", 0, search::query::Weight(0)}; } } @@ -1252,7 +1251,7 @@ TEST("require that children does not optimize when parents refuse them to") { SearchIterator::UP search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::BitVectorIteratorStrictT<false>", e.getChildren()[0]->getClassName()); EXPECT_EQUAL("search::diskindex::ZcRareWordPosOccIterator<true, false>", e.getChildren()[1]->getClassName()); EXPECT_EQUAL("search::diskindex::ZcRareWordPosOccIterator<true, false>", e.getChildren()[2]->getClassName()); @@ -1262,7 +1261,7 @@ TEST("require that children does not optimize when parents refuse them to") { search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::BitVectorIteratorStrictT<false>", e.getChildren()[0]->getClassName()); EXPECT_EQUAL("search::diskindex::ZcRareWordPosOccIterator<true, false>", e.getChildren()[1]->getClassName()); EXPECT_EQUAL("search::diskindex::ZcRareWordPosOccIterator<true, false>", e.getChildren()[2]->getClassName()); @@ -1290,7 +1289,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { SearchIterator::UP search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::queryeval::OrLikeSearch<true, search::queryeval::(anonymous namespace)::FullUnpack>", e.getChildren()[0]->getClassName()); } @@ -1299,7 +1298,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::queryeval::OrLikeSearch<true, search::queryeval::(anonymous namespace)::SelectiveUnpack>", e.getChildren()[0]->getClassName()); } @@ -1309,7 +1308,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::queryeval::OrLikeSearch<true, search::queryeval::NoUnpack>", e.getChildren()[0]->getClassName()); } @@ -1365,7 +1364,7 @@ TEST("require that children of onear are not optimized") { TEST("require that ANDNOT without children is optimized to empty search") { Blueprint::UP top_up(new AndNotBlueprint()); - Blueprint::UP expect_up(new EmptyBlueprint()); + auto expect_up = std::make_unique<EmptyBlueprint>(); top_up = Blueprint::optimize(std::move(top_up)); EXPECT_EQUAL(expect_up->asString(), top_up->asString()); } diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp index e006a95ae5f..aba80faaa8a 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp @@ -117,7 +117,7 @@ Blueprint::State::State(FieldSpecBaseList fields_in) noexcept Blueprint::State::~State() = default; Blueprint::Blueprint() noexcept - : _parent(0), + : _parent(nullptr), _sourceId(0xffffffff), _docid_limit(0), _frozen(false) @@ -141,7 +141,7 @@ Blueprint::optimize_self() Blueprint::UP Blueprint::get_replacement() { - return Blueprint::UP(); + return {}; } void @@ -163,8 +163,8 @@ std::unique_ptr<MatchingElementsSearch> Blueprint::create_matching_elements_search(const MatchingElementsFields &fields) const { (void) fields; - return std::unique_ptr<MatchingElementsSearch>(); -}; + return {}; +} namespace { @@ -196,7 +196,7 @@ template <typename Op> std::unique_ptr<SearchIterator> create_op_filter(const Blueprint::Children &children, bool strict, Blueprint::FilterConstraint constraint) { - REQUIRE(children.size() > 0); + REQUIRE( ! children.empty()); MultiSearch::Children list; std::unique_ptr<SearchIterator> spare; list.reserve(children.size()); @@ -261,7 +261,7 @@ Blueprint::create_atmost_or_filter(const Children &children, bool strict, Bluepr std::unique_ptr<SearchIterator> Blueprint::create_andnot_filter(const Children &children, bool strict, Blueprint::FilterConstraint constraint) { - REQUIRE(children.size() > 0); + REQUIRE( ! children.empty() ); MultiSearch::Children list; list.reserve(children.size()); { @@ -291,7 +291,7 @@ Blueprint::create_andnot_filter(const Children &children, bool strict, Blueprint std::unique_ptr<SearchIterator> Blueprint::create_first_child_filter(const Children &children, bool strict, Blueprint::FilterConstraint constraint) { - REQUIRE(children.size() > 0); + REQUIRE(!children.empty()); return children[0]->createFilterSearch(strict, constraint); } @@ -434,7 +434,7 @@ IntermediateBlueprint::infer_allow_termwise_eval() const } } return true; -}; +} bool IntermediateBlueprint::infer_want_global_filter() const @@ -640,11 +640,7 @@ namespace { bool areAnyParentsEquiv(const Blueprint * node) { - return (node == nullptr) - ? false - : node->isEquiv() - ? true - : areAnyParentsEquiv(node->getParent()); + return (node != nullptr) && (node->isEquiv() || areAnyParentsEquiv(node->getParent())); } bool @@ -767,7 +763,7 @@ LeafBlueprint::set_tree_size(uint32_t value) void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const search::queryeval::Blueprint *obj) { - if (obj != 0) { + if (obj != nullptr) { self.openStruct(name, obj->getClassName()); obj->visitMembers(self); self.closeStruct(); diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.h b/searchlib/src/vespa/searchlib/queryeval/blueprint.h index c9ebab7ae9d..da6050f075d 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.h @@ -79,8 +79,8 @@ public: static constexpr uint8_t COST_TIER_MAX = 255; State() noexcept; - State(FieldSpecBase field) noexcept; - State(FieldSpecBaseList fields_in) noexcept; + explicit State(FieldSpecBase field) noexcept; + explicit State(FieldSpecBaseList fields_in) noexcept; State(const State &rhs) = delete; State(State &&rhs) noexcept = default; State &operator=(const State &rhs) = delete; @@ -105,7 +105,7 @@ public: _estimateHits = est.estHits; _estimateEmpty = est.empty; } - HitEstimate estimate() const noexcept { return HitEstimate(_estimateHits, _estimateEmpty); } + HitEstimate estimate() const noexcept { return {_estimateHits, _estimateEmpty}; } double hit_ratio(uint32_t docid_limit) const noexcept { uint32_t total_hits = _estimateHits; uint32_t total_docs = std::max(total_hits, docid_limit); @@ -374,7 +374,7 @@ protected: void set_want_global_filter(bool value); void set_tree_size(uint32_t value); - LeafBlueprint(bool allow_termwise_eval) noexcept + explicit LeafBlueprint(bool allow_termwise_eval) noexcept : _state() { _state.allow_termwise_eval(allow_termwise_eval); diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp index 95c1c05c8d0..790d61b3731 100644 --- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp @@ -607,7 +607,7 @@ RankBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) cons //----------------------------------------------------------------------------- -SourceBlenderBlueprint::SourceBlenderBlueprint(const ISourceSelector &selector) +SourceBlenderBlueprint::SourceBlenderBlueprint(const ISourceSelector &selector) noexcept : _selector(selector) { } @@ -637,27 +637,6 @@ SourceBlenderBlueprint::inheritStrict(size_t) const return true; } -class FindSource : public Blueprint::IPredicate -{ -public: - explicit FindSource(uint32_t sourceId) noexcept : _sourceId(sourceId) { } - bool check(const Blueprint & bp) const override { return bp.getSourceId() == _sourceId; } -private: - uint32_t _sourceId; -}; - -ssize_t -SourceBlenderBlueprint::findSource(uint32_t sourceId) const -{ - ssize_t index(-1); - FindSource fs(sourceId); - IndexList list = find(fs); - if ( ! list.empty()) { - index = list.front(); - } - return index; -} - SearchIterator::UP SourceBlenderBlueprint::createIntermediateSearch(MultiSearch::Children sub_searches, bool strict, search::fef::MatchData &) const diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h index 02803877c19..409a9e0fe95 100644 --- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h +++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h @@ -97,8 +97,8 @@ public: bool strict, fef::MatchData &md) const override; SearchIterator::UP createFilterSearch(bool strict, FilterConstraint constraint) const override; - WeakAndBlueprint(uint32_t n) : _n(n) {} - ~WeakAndBlueprint(); + explicit WeakAndBlueprint(uint32_t n) noexcept : _n(n) {} + ~WeakAndBlueprint() override; void addTerm(Blueprint::UP bp, uint32_t weight) { addChild(std::move(bp)); _weights.push_back(weight); @@ -126,7 +126,7 @@ public: bool strict, fef::MatchData &md) const override; SearchIterator::UP createFilterSearch(bool strict, FilterConstraint constraint) const override; - NearBlueprint(uint32_t window) : _window(window) {} + explicit NearBlueprint(uint32_t window) noexcept : _window(window) {} }; //----------------------------------------------------------------------------- @@ -148,7 +148,7 @@ public: bool strict, fef::MatchData &md) const override; SearchIterator::UP createFilterSearch(bool strict, FilterConstraint constraint) const override; - ONearBlueprint(uint32_t window) : _window(window) {} + explicit ONearBlueprint(uint32_t window) noexcept : _window(window) {} }; //----------------------------------------------------------------------------- @@ -178,18 +178,12 @@ private: const ISourceSelector &_selector; public: - SourceBlenderBlueprint(const ISourceSelector &selector); + explicit SourceBlenderBlueprint(const ISourceSelector &selector) noexcept; ~SourceBlenderBlueprint() override; HitEstimate combine(const std::vector<HitEstimate> &data) const override; FieldSpecBaseList exposeFields() const override; void sort(Children &children) const override; bool inheritStrict(size_t i) const override; - /** - * Will return the index matching the given sourceId. - * @param sourceId The sourceid to find. - * @return The index to the child representing the sourceId. -1 if not found. - */ - ssize_t findSource(uint32_t sourceId) const; SearchIterator::UP createIntermediateSearch(MultiSearch::Children subSearches, bool strict, fef::MatchData &md) const override; |