summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-03-30 11:18:31 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-03-30 11:18:31 +0000
commit8cc305708ab15a2884493f32a7811247ba02e209 (patch)
tree5bbc2f1ea0d602af12fd38126bc6905ee2c68b93 /searchlib
parent6cf77fb52faedeca24fda94aa51e70056c268de9 (diff)
Avoid dynamic cast
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp18
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/blueprint.h3
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp18
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h10
4 files changed, 26 insertions, 23 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
index 0672e51378e..34ab547b85d 100644
--- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
@@ -43,7 +43,7 @@ public:
createIntermediateSearch(MultiSearch::Children subSearches,
bool strict, MatchData &md) const override
{
- return SearchIterator::UP(new MySearch("or", std::move(subSearches), &md, strict));
+ return std::make_unique<MySearch>("or", std::move(subSearches), &md, strict);
}
static MyOr& create() { return *(new MyOr()); }
@@ -60,7 +60,7 @@ public:
createIntermediateSearch(MultiSearch::Children subSearches,
bool strict, MatchData &md) const override
{
- return SearchIterator::UP(new MySearch("or", std::move(subSearches), &md, strict));
+ return std::make_unique<MySearch>("or", std::move(subSearches), &md, strict);
}
static OtherOr& create() { return *(new OtherOr()); }
@@ -74,15 +74,15 @@ class MyAnd : public AndBlueprint
{
private:
public:
- virtual HitEstimate combine(const std::vector<HitEstimate> &data) const override {
+ HitEstimate combine(const std::vector<HitEstimate> &data) const override {
return min(data);
}
- virtual FieldSpecBaseList exposeFields() const override {
+ FieldSpecBaseList exposeFields() const override {
return FieldSpecBaseList();
}
- virtual bool inheritStrict(size_t i) const override {
+ bool inheritStrict(size_t i) const override {
return (i == 0);
}
@@ -90,7 +90,7 @@ public:
createIntermediateSearch(MultiSearch::Children subSearches,
bool strict, MatchData &md) const override
{
- return SearchIterator::UP(new MySearch("and", std::move(subSearches), &md, strict));
+ return std::make_unique<MySearch>("and", std::move(subSearches), &md, strict);
}
static MyAnd& create() { return *(new MyAnd()); }
@@ -107,7 +107,7 @@ public:
createIntermediateSearch(MultiSearch::Children subSearches,
bool strict, MatchData &md) const override
{
- return SearchIterator::UP(new MySearch("and", std::move(subSearches), &md, strict));
+ return std::make_unique<MySearch>("and", std::move(subSearches), &md, strict);
}
static OtherAnd& create() { return *(new OtherAnd()); }
@@ -122,7 +122,7 @@ public:
createIntermediateSearch(MultiSearch::Children subSearches,
bool strict, MatchData &md) const override
{
- return SearchIterator::UP(new MySearch("andnot", std::move(subSearches), &md, strict));
+ return std::make_unique<MySearch>("andnot", std::move(subSearches), &md, strict);
}
static OtherAndNot& create() { return *(new OtherAndNot()); }
@@ -641,7 +641,7 @@ Test::testSearchCreation()
template<typename T>
Blueprint::UP makeNew(T *orig)
{
- return Blueprint::UP(new T(*orig));
+ return std::make_unique<T>(*orig);
}
void
diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.h b/searchlib/src/vespa/searchlib/queryeval/blueprint.h
index 722b3701881..bf89fe85891 100644
--- a/searchlib/src/vespa/searchlib/queryeval/blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.h
@@ -220,6 +220,9 @@ public:
virtual bool isEquiv() const { return false; }
virtual bool isWhiteList() const { return false; }
virtual bool isIntermediate() const { return false; }
+ virtual bool isAnd() const { return false; }
+ virtual bool isAndNot() const { return false; }
+ virtual bool isOr() const { return false; }
virtual const attribute::ISearchContext *get_attribute_search_context() const { return nullptr; }
// For document summaries with matched-elements-only set.
diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp
index 3f632cfc377..b61836c2fd3 100644
--- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp
@@ -117,8 +117,8 @@ AndNotBlueprint::optimize_self()
if (childCnt() == 0) {
return;
}
- AndNotBlueprint *child = dynamic_cast<AndNotBlueprint *>(&getChild(0));
- if (child != nullptr) {
+ if (getChild(0).isAndNot()) {
+ AndNotBlueprint *child = static_cast<AndNotBlueprint *>(&getChild(0));
while (child->childCnt() > 1) {
addChild(child->removeChild(1));
}
@@ -130,7 +130,7 @@ AndNotBlueprint::optimize_self()
removeChild(i--);
}
}
- if (dynamic_cast<AndNotBlueprint *>(getParent()) == nullptr) {
+ if ( !(getParent() && getParent()->isAndNot()) ) {
optimize_source_blenders<OrBlueprint>(*this, 1);
}
}
@@ -224,15 +224,15 @@ void
AndBlueprint::optimize_self()
{
for (size_t i = 0; i < childCnt(); ++i) {
- AndBlueprint *child = dynamic_cast<AndBlueprint *>(&getChild(i));
- if (child != nullptr) {
+ if (getChild(i).isAnd()) {
+ AndBlueprint *child = static_cast<AndBlueprint *>(&getChild(i));
while (child->childCnt() > 0) {
addChild(child->removeChild(0));
}
removeChild(i--);
}
}
- if (dynamic_cast<AndBlueprint *>(getParent()) == nullptr) {
+ if ( !(getParent() && getParent()->isAnd()) ) {
optimize_source_blenders<AndBlueprint>(*this, 0);
}
}
@@ -311,8 +311,8 @@ void
OrBlueprint::optimize_self()
{
for (size_t i = 0; (childCnt() > 1) && (i < childCnt()); ++i) {
- OrBlueprint *child = dynamic_cast<OrBlueprint *>(&getChild(i));
- if (child != nullptr) {
+ if (getChild(i).isOr()) {
+ OrBlueprint *child = static_cast<OrBlueprint *>(&getChild(i));
while (child->childCnt() > 0) {
addChild(child->removeChild(0));
}
@@ -321,7 +321,7 @@ OrBlueprint::optimize_self()
removeChild(i--);
}
}
- if (dynamic_cast<OrBlueprint *>(getParent()) == nullptr) {
+ if ( !(getParent() && getParent()->isOr()) ) {
optimize_source_blenders<OrBlueprint>(*this, 0);
}
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h
index bc635952d55..3dd4ccbb60f 100644
--- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h
+++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h
@@ -18,6 +18,7 @@ public:
HitEstimate combine(const std::vector<HitEstimate> &data) const override;
FieldSpecBaseList exposeFields() const override;
void optimize_self() override;
+ bool isAndNot() const override { return true; }
Blueprint::UP get_replacement() override;
void sort(std::vector<Blueprint*> &children) const override;
bool inheritStrict(size_t i) const override;
@@ -40,11 +41,7 @@ public:
HitEstimate combine(const std::vector<HitEstimate> &data) const override;
FieldSpecBaseList exposeFields() const override;
void optimize_self() override;
-
-private:
- double computeNextHitRate(const Blueprint & child, double hitRate) const override;
-
-public:
+ bool isAnd() const override { return true; }
Blueprint::UP get_replacement() override;
void sort(std::vector<Blueprint*> &children) const override;
bool inheritStrict(size_t i) const override;
@@ -53,6 +50,8 @@ public:
bool strict, fef::MatchData &md) const override;
SearchIterator::UP
createFilterSearch(bool strict, FilterConstraint constraint) const override;
+private:
+ double computeNextHitRate(const Blueprint & child, double hitRate) const override;
};
//-----------------------------------------------------------------------------
@@ -65,6 +64,7 @@ public:
HitEstimate combine(const std::vector<HitEstimate> &data) const override;
FieldSpecBaseList exposeFields() const override;
void optimize_self() override;
+ bool isOr() const override { return true; }
Blueprint::UP get_replacement() override;
void sort(std::vector<Blueprint*> &children) const override;
bool inheritStrict(size_t i) const override;