diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-12-12 13:47:11 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-12-12 13:47:11 +0000 |
commit | 81487d4843b65c66f2f14a3346f3b6b51b85e245 (patch) | |
tree | f5fd47779d893464b0938eac46a2d12afd9b1daf | |
parent | 3f54d4088502406eda15288bde29a16f6c810751 (diff) |
Unify on using reference where possible.
14 files changed, 49 insertions, 47 deletions
diff --git a/searchcore/src/tests/proton/matching/match_phase_limiter/match_phase_limiter_test.cpp b/searchcore/src/tests/proton/matching/match_phase_limiter/match_phase_limiter_test.cpp index 67490c03985..824ee891873 100644 --- a/searchcore/src/tests/proton/matching/match_phase_limiter/match_phase_limiter_test.cpp +++ b/searchcore/src/tests/proton/matching/match_phase_limiter/match_phase_limiter_test.cpp @@ -69,7 +69,7 @@ struct MockBlueprint : SimpleLeafBlueprint { FieldSpec spec; vespalib::string term; bool postings_fetched = false; - search::queryeval::ExecuteInfo postings_strict = search::queryeval::ExecuteInfo::FALSE; + bool postings_strict = false; MockBlueprint(const FieldSpec &spec_in, const vespalib::string &term_in) : SimpleLeafBlueprint(spec_in), spec(spec_in), term(term_in) { @@ -78,7 +78,7 @@ struct MockBlueprint : SimpleLeafBlueprint { SearchIterator::UP createLeafSearch(const TermFieldMatchDataArray &tfmda, bool strict) const override { if (postings_fetched) { - EXPECT_EQUAL(postings_strict.is_strict(), strict); + EXPECT_EQUAL(postings_strict, strict); } return std::make_unique<MockSearch>(spec, term, strict, tfmda, postings_fetched); } @@ -86,7 +86,7 @@ struct MockBlueprint : SimpleLeafBlueprint { return create_default_filter(strict, constraint); } void fetchPostings(const search::queryeval::ExecuteInfo &execInfo) override { - postings_strict = execInfo; + postings_strict = execInfo.is_strict(); postings_fetched = true; } }; diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp index dc1596b9d16..527f7702a7c 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp @@ -208,7 +208,7 @@ MatchToolsFactory(QueryLimiter & queryLimiter, double hitRate = std::min(1.0, double(maxNumHits)/double(searchContext.getDocIdLimit())); bool create_postinglist_when_non_strict = CreatePostingListWhenNonStrict::check(_queryEnv.getProperties(), rankSetup.create_postinglist_when_non_strict()); bool use_estimate_for_fetch_postings = UseEstimateForFetchPostings::check(_queryEnv.getProperties(), rankSetup.use_estimate_for_fetch_postings()); - _query.fetchPostings(ExecuteInfo::create(is_search, hitRate, &_requestContext.getDoom(), &thread_bundle, + _query.fetchPostings(ExecuteInfo::create(is_search, hitRate, &_requestContext.getDoom(), thread_bundle, create_postinglist_when_non_strict, use_estimate_for_fetch_postings)); if (is_search) { _query.handle_global_filter(_requestContext, searchContext.getDocIdLimit(), diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.cpp b/searchcore/src/vespa/searchcore/proton/matching/query.cpp index 451a891312c..027625a2a57 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/query.cpp @@ -217,7 +217,7 @@ Query::handle_global_filter(const IRequestContext & requestContext, uint32_t doc bool create_postinglist_when_non_strict, bool use_estimate_for_fetch_postings) { if (!handle_global_filter(*_blueprint, docid_limit, global_filter_lower_limit, global_filter_upper_limit, - *requestContext.thread_bundle(), &trace)) + requestContext.thread_bundle(), &trace)) { return; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h index d843035791d..c2721fd18ed 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h +++ b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h @@ -31,7 +31,7 @@ public: const MetaStoreReadGuardSP * metaStoreReadGuard); const Doom & getDoom() const override { return _doom; } - vespalib::ThreadBundle * thread_bundle() const override { return &_thread_bundle; } + vespalib::ThreadBundle & thread_bundle() const override { return _thread_bundle; } const search::attribute::IAttributeVector *getAttribute(const vespalib::string &name) const override; void asyncForAttribute(const vespalib::string &name, std::unique_ptr<IAttributeFunctor> func) const override; diff --git a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp index bd6dc6da558..5d5348de52a 100644 --- a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp +++ b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp @@ -38,7 +38,7 @@ public: explicit WarmupRequestContext(const vespalib::Clock & clock); ~WarmupRequestContext() override; const vespalib::Doom & getDoom() const override { return _doom; } - vespalib::ThreadBundle * thread_bundle() const override { return nullptr; } + vespalib::ThreadBundle & thread_bundle() const override { return vespalib::ThreadBundle::trivial(); } const IAttributeVector *getAttribute(const vespalib::string &) const override { return nullptr; } const IAttributeVector *getAttributeStableEnum(const vespalib::string &) const override { return nullptr; } const vespalib::eval::Value* get_query_tensor(const vespalib::string&) const override; diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp index 27f2f3bb5d0..7d994ee4cd6 100644 --- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp @@ -39,13 +39,16 @@ struct WeightOrder { }; struct RememberExecuteInfo : public MyLeaf { - ExecuteInfo executeInfo; + bool is_strict; + double hit_rate; - using MyLeaf::MyLeaf; + RememberExecuteInfo() : MyLeaf(), is_strict(false), hit_rate(0.0) {} + RememberExecuteInfo(FieldSpecBaseList fields) : MyLeaf(std::move(fields)), is_strict(false), hit_rate(0.0) {} void fetchPostings(const ExecuteInfo &execInfo) override { LeafBlueprint::fetchPostings(execInfo); - executeInfo = execInfo; + is_strict = execInfo.is_strict(); + hit_rate = execInfo.hit_rate(); } }; @@ -134,11 +137,11 @@ TEST("test And propagates updated histestimate") { EXPECT_EQUAL(3u, bp->childCnt()); for (uint32_t i = 0; i < bp->childCnt(); i++) { const auto & child = dynamic_cast<const RememberExecuteInfo &>(bp->getChild(i)); - EXPECT_EQUAL((i == 0), child.executeInfo.is_strict()); + EXPECT_EQUAL((i == 0), child.is_strict); } - EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).executeInfo.hit_rate()); - EXPECT_EQUAL(1.0/250, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).executeInfo.hit_rate()); - EXPECT_EQUAL(1.0/(250*25), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).executeInfo.hit_rate()); + EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).hit_rate); + EXPECT_EQUAL(1.0/250, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).hit_rate); + EXPECT_EQUAL(1.0/(250*25), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).hit_rate); } TEST("test Or propagates updated histestimate") { @@ -154,12 +157,12 @@ TEST("test Or propagates updated histestimate") { EXPECT_EQUAL(4u, bp->childCnt()); for (uint32_t i = 0; i < bp->childCnt(); i++) { const auto & child = dynamic_cast<const RememberExecuteInfo &>(bp->getChild(i)); - EXPECT_TRUE(child.executeInfo.is_strict()); + EXPECT_TRUE(child.is_strict); } - EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).executeInfo.hit_rate()); - EXPECT_APPROX(0.5, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).executeInfo.hit_rate(), 1e-6); - EXPECT_APPROX(0.5*3.0/5.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).executeInfo.hit_rate(), 1e-6); - EXPECT_APPROX(0.5*3.0*42.0/(5.0*50.0), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(3)).executeInfo.hit_rate(), 1e-6); + EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).hit_rate); + EXPECT_APPROX(0.5, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).hit_rate, 1e-6); + EXPECT_APPROX(0.5*3.0/5.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).hit_rate, 1e-6); + EXPECT_APPROX(0.5*3.0*42.0/(5.0*50.0), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(3)).hit_rate, 1e-6); } TEST("test And Blueprint") { diff --git a/searchlib/src/tests/queryeval/blueprint/mysearch.h b/searchlib/src/tests/queryeval/blueprint/mysearch.h index 6cfc7a04368..db7dd2adae6 100644 --- a/searchlib/src/tests/queryeval/blueprint/mysearch.h +++ b/searchlib/src/tests/queryeval/blueprint/mysearch.h @@ -58,10 +58,10 @@ public: if (!_isLeaf) { ok &= (_md == &md); } - for (size_t i = 0; i < _children.size(); ++i) { - MySearch *child = dynamic_cast<MySearch *>(_children[i].get()); - ok &= (child != 0); - if (child != 0) { + for (const auto & my_search : _children) { + auto *child = dynamic_cast<MySearch *>(my_search.get()); + ok &= (child != nullptr); + if (child != nullptr) { ok &= child->verifyAndInferImpl(md); } } @@ -80,8 +80,8 @@ public: } static bool verifyAndInfer(SearchIterator *search, MatchData &md) { - MySearch *self = dynamic_cast<MySearch *>(search); - if (self == 0) { + auto *self = dynamic_cast<MySearch *>(search); + if (self == nullptr) { return false; } else { return self->verifyAndInferImpl(md); diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp index 117a1dfa7c5..ecdfad433ee 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp @@ -62,8 +62,7 @@ void PostingListSearchContextT<DataT>::fillArray() { for (auto it(_lowerDictItr); it != _upperDictItr; ++it) { - _merger.addToArray(PostingListTraverser<PostingStore>(_posting_store, - it.getData().load_acquire())); + _merger.addToArray(PostingListTraverser<PostingStore>(_posting_store, it.getData().load_acquire())); } _merger.merge(); } diff --git a/searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp b/searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp index f5794b86486..858cb92331a 100644 --- a/searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/executeinfo.cpp @@ -4,7 +4,7 @@ namespace search::queryeval { -const ExecuteInfo ExecuteInfo::TRUE(true, 1.0, nullptr, nullptr, true, true); -const ExecuteInfo ExecuteInfo::FALSE(false, 1.0, nullptr, nullptr, true, true); +const ExecuteInfo ExecuteInfo::TRUE(true, 1.0, nullptr, vespalib::ThreadBundle::trivial(), true, true); +const ExecuteInfo ExecuteInfo::FALSE(false, 1.0, nullptr, vespalib::ThreadBundle::trivial(), true, true); } diff --git a/searchlib/src/vespa/searchlib/queryeval/executeinfo.h b/searchlib/src/vespa/searchlib/queryeval/executeinfo.h index 3cb6a5654f2..3300a2aea4d 100644 --- a/searchlib/src/vespa/searchlib/queryeval/executeinfo.h +++ b/searchlib/src/vespa/searchlib/queryeval/executeinfo.h @@ -13,14 +13,13 @@ namespace search::queryeval { */ class ExecuteInfo { public: - ExecuteInfo() noexcept : ExecuteInfo(false, 1.0, nullptr, nullptr, true, true) { } + ExecuteInfo() noexcept : ExecuteInfo(false, 1.0, nullptr, vespalib::ThreadBundle::trivial(), true, true) { } bool is_strict() const noexcept { return _strict; } bool create_postinglist_when_non_strict() const noexcept { return _create_postinglist_when_non_strict; } bool use_estimate_for_fetch_postings() const noexcept { return _use_estimate_for_fetch_postings; } double hit_rate() const noexcept { return _hitRate; } bool soft_doom() const noexcept { return _doom && _doom->soft_doom(); } - const vespalib::Doom * doom() const noexcept { return _doom; } - vespalib::ThreadBundle * thread_bundle() const noexcept { return _thread_bundle; } + vespalib::ThreadBundle & thread_bundle() const noexcept { return _thread_bundle; } static const ExecuteInfo TRUE; static const ExecuteInfo FALSE; @@ -28,10 +27,10 @@ public: return create(strict, org._hitRate, org); } static ExecuteInfo create(bool strict, double hitRate, const ExecuteInfo & org) noexcept { - return {strict, hitRate, org.doom(), org.thread_bundle(), org.create_postinglist_when_non_strict(), org.use_estimate_for_fetch_postings()}; + return {strict, hitRate, org._doom, org.thread_bundle(), org.create_postinglist_when_non_strict(), org.use_estimate_for_fetch_postings()}; } - static ExecuteInfo create(bool strict, double hitRate, const vespalib::Doom * doom, vespalib::ThreadBundle * thread_bundle_in, + static ExecuteInfo create(bool strict, double hitRate, const vespalib::Doom * doom, vespalib::ThreadBundle & thread_bundle_in, bool postinglist_when_non_strict, bool use_estimate_for_fetch_postings) noexcept { return {strict, hitRate, doom, thread_bundle_in, postinglist_when_non_strict, use_estimate_for_fetch_postings}; @@ -43,10 +42,10 @@ public: return createForTest(strict, hitRate, nullptr); } static ExecuteInfo createForTest(bool strict, double hitRate, const vespalib::Doom * doom) noexcept { - return create(strict, hitRate, doom, nullptr, true, true); + return create(strict, hitRate, doom, vespalib::ThreadBundle::trivial(), true, true); } private: - ExecuteInfo(bool strict, double hitRate_in, const vespalib::Doom * doom, vespalib::ThreadBundle * thread_bundle_in, + ExecuteInfo(bool strict, double hitRate_in, const vespalib::Doom * doom, vespalib::ThreadBundle & thread_bundle_in, bool postinglist_when_non_strict, bool use_estimate_for_fetch_postings) noexcept : _doom(doom), _thread_bundle(thread_bundle_in), @@ -56,7 +55,7 @@ private: _use_estimate_for_fetch_postings(use_estimate_for_fetch_postings) { } const vespalib::Doom * _doom; - vespalib::ThreadBundle * _thread_bundle; + vespalib::ThreadBundle & _thread_bundle; double _hitRate; bool _strict; bool _create_postinglist_when_non_strict; diff --git a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h index 0812f6c403d..0122352656e 100644 --- a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h +++ b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h @@ -11,6 +11,7 @@ #include <vespa/searchlib/attribute/attributevector.h> #include <vespa/searchlib/attribute/attribute_blueprint_params.h> #include <vespa/vespalib/util/doom.h> +#include <vespa/vespalib/util/thread_bundle.h> #include <limits> namespace vespalib { class TestClock; } @@ -25,7 +26,7 @@ public: vespalib::steady_time hard=vespalib::steady_time::max()); ~FakeRequestContext() override; const vespalib::Doom & getDoom() const override { return _doom; } - vespalib::ThreadBundle * thread_bundle() const override { return nullptr; } + vespalib::ThreadBundle & thread_bundle() const override { return vespalib::ThreadBundle::trivial(); } const attribute::IAttributeVector *getAttribute(const vespalib::string &name) const override { return _attributeContext ? _attributeContext->getAttribute(name) diff --git a/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h b/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h index 768f36ded1e..ad25385be4b 100644 --- a/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h +++ b/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h @@ -32,7 +32,7 @@ public: /** * Provide an optional thread bundle that can be used for multithreading parts of the query. */ - virtual vespalib::ThreadBundle * thread_bundle() const = 0; + virtual vespalib::ThreadBundle & thread_bundle() const = 0; /** * Provide access to attributevectors diff --git a/vespalib/src/vespa/vespalib/util/doom.cpp b/vespalib/src/vespa/vespalib/util/doom.cpp index 01ad3aa4e97..227d43ee4c4 100644 --- a/vespalib/src/vespa/vespalib/util/doom.cpp +++ b/vespalib/src/vespa/vespalib/util/doom.cpp @@ -5,7 +5,7 @@ namespace vespalib { Doom::Doom(const Clock &clock, steady_time softDoom, - steady_time hardDoom, bool explicitSoftDoom) + steady_time hardDoom, bool explicitSoftDoom) noexcept : _clock(clock), _softDoom(softDoom), _hardDoom(hardDoom), diff --git a/vespalib/src/vespa/vespalib/util/doom.h b/vespalib/src/vespa/vespalib/util/doom.h index cbac7e2cfbd..a175bbd20df 100644 --- a/vespalib/src/vespa/vespalib/util/doom.h +++ b/vespalib/src/vespa/vespalib/util/doom.h @@ -8,17 +8,17 @@ namespace vespalib { class Doom { public: - Doom(const Clock &clock, steady_time doom) + Doom(const Clock &clock, steady_time doom) noexcept : Doom(clock, doom, doom, false) {} Doom(const Clock &clock, steady_time softDoom, - steady_time hardDoom, bool explicitSoftDoom); + steady_time hardDoom, bool explicitSoftDoom) noexcept; - bool soft_doom() const { return (_clock.getTimeNS() > _softDoom); } - bool hard_doom() const { return (_clock.getTimeNS() > _hardDoom); } - duration soft_left() const { return _softDoom - _clock.getTimeNS(); } - duration hard_left() const { return _hardDoom - _clock.getTimeNS(); } - bool isExplicitSoftDoom() const { return _isExplicitSoftDoom; } + bool soft_doom() const noexcept { return (_clock.getTimeNS() > _softDoom); } + bool hard_doom() const noexcept { return (_clock.getTimeNS() > _hardDoom); } + duration soft_left() const noexcept { return _softDoom - _clock.getTimeNS(); } + duration hard_left() const noexcept { return _hardDoom - _clock.getTimeNS(); } + bool isExplicitSoftDoom() const noexcept { return _isExplicitSoftDoom; } private: const Clock &_clock; steady_time _softDoom; |