diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-30 14:55:49 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-30 14:55:49 +0000 |
commit | 59db6ce6df3e819d9c2d804ee46d3bdc1491c762 (patch) | |
tree | 4c953947335d6ae58176d001a125e6056612862e /document | |
parent | e2d42bca66c0fdeee60e3c21a2517c9cb80efe6b (diff) |
Rewrite to do initialization in constructor.
Diffstat (limited to 'document')
-rw-r--r-- | document/src/vespa/document/select/cloningvisitor.cpp | 7 | ||||
-rw-r--r-- | document/src/vespa/document/select/result.h | 7 | ||||
-rw-r--r-- | document/src/vespa/document/select/resultset.cpp | 36 | ||||
-rw-r--r-- | document/src/vespa/document/select/resultset.h | 35 |
4 files changed, 29 insertions, 56 deletions
diff --git a/document/src/vespa/document/select/cloningvisitor.cpp b/document/src/vespa/document/select/cloningvisitor.cpp index 81cb31145ec..cc9e8dfdd42 100644 --- a/document/src/vespa/document/select/cloningvisitor.cpp +++ b/document/src/vespa/document/select/cloningvisitor.cpp @@ -35,7 +35,6 @@ CloningVisitor::visitAndBranch(const And &expr) revisit(); expr.getRight().visit(*this); _constVal &= lhsConstVal; - _resultSet.calcAnd(lhsSet); setNodeParentheses(priority); std::unique_ptr<Node> rhs(std::move(_node)); _priority = priority; @@ -55,7 +54,6 @@ CloningVisitor::visitOrBranch(const Or &expr) revisit(); expr.getRight().visit(*this); _constVal &= lhsConstVal; - _resultSet.calcOr(lhsSet); setNodeParentheses(priority); std::unique_ptr<Node> rhs(std::move(_node)); _priority = priority; @@ -69,7 +67,6 @@ CloningVisitor::visitNotBranch(const Not &expr) int priority = ComparePriority; expr.getChild().visit(*this); setNodeParentheses(priority); - _resultSet.calcNot(); std::unique_ptr<Node> child(std::move(_node)); _priority = priority; _node = std::make_unique<Not>(std::move(child), "not"); @@ -311,9 +308,7 @@ CloningVisitor::setArithmeticValueNode(const ArithmeticValueNode &expr, rhs->setParentheses(); } _priority = priority; - _valueNode.reset(new ArithmeticValueNode(std::move(lhs), - expr.getOperatorName(), - std::move(rhs))); + _valueNode = std::make_unique<ArithmeticValueNode>(std::move(lhs), expr.getOperatorName(), std::move(rhs)); } diff --git a/document/src/vespa/document/select/result.h b/document/src/vespa/document/select/result.h index 151b1eb9d3c..e09a7908b69 100644 --- a/document/src/vespa/document/select/result.h +++ b/document/src/vespa/document/select/result.h @@ -29,6 +29,10 @@ public: static Result False; static Result True; + // Singletons are not copyable + Result(const Result&) = delete; + Result& operator=(const Result&) = delete; + void print(std::ostream& out, bool verbose, const std::string& indent) const override; bool operator==(const Result& o) const { return (&o == this); } @@ -63,9 +67,6 @@ public: private: Result(); - // Singletons are not copyable - Result(const Result&) = delete; - Result& operator=(const Result&) = delete; }; } diff --git a/document/src/vespa/document/select/resultset.cpp b/document/src/vespa/document/select/resultset.cpp index 20e2f84705d..79133e5ca3d 100644 --- a/document/src/vespa/document/select/resultset.cpp +++ b/document/src/vespa/document/select/resultset.cpp @@ -4,27 +4,18 @@ namespace document::select { -std::vector<ResultSet> ResultSet::_ands; -std::vector<ResultSet> ResultSet::_ors; -std::vector<ResultSet> ResultSet::_nots; +const ResultSet::PreCalculated ResultSet::_preCalc(ResultSet::illegalMask()); /* * Precalculate possible outcomes of boolean operations, given possible * inputs. */ -void -ResultSet::preCalc() +ResultSet::PreCalculated::PreCalculated(uint32_t range) + : _ands(range * range), + _ors(range * range), + _nots(range) { uint32_t erange = Result::enumRange; - uint32_t range = illegalMask(); - _ands.resize(range * range); - _ors.resize(range * range); -#pragma GCC diagnostic push -#if !defined(__clang__) && __GNUC__ == 13 -#pragma GCC diagnostic ignored "-Wstringop-overflow=" -#endif - _nots.resize(range); -#pragma GCC diagnostic pop for (ResultSet lset; lset.pcvalid(); lset.pcnext()) { for (ResultSet rset; rset.pcvalid(); rset.pcnext()) { ResultSet myand; @@ -55,21 +46,6 @@ ResultSet::preCalc() } } - -namespace { - -class Precalc -{ -public: - Precalc() - { - ResultSet::preCalc(); - } -}; - - -Precalc precalc; - -} +ResultSet::PreCalculated::~PreCalculated() = default; } diff --git a/document/src/vespa/document/select/resultset.h b/document/src/vespa/document/select/resultset.h index 1289f61046c..36939ac2551 100644 --- a/document/src/vespa/document/select/resultset.h +++ b/document/src/vespa/document/select/resultset.h @@ -16,17 +16,22 @@ class ResultSet uint8_t _val; // range [0..7], cf. Result::toEnum() // Precalculated results for boolean operations on Result. - static std::vector<ResultSet> _ands; - static std::vector<ResultSet> _ors; - static std::vector<ResultSet> _nots; + struct PreCalculated { + PreCalculated(uint32_t range); + ~PreCalculated(); + std::vector<ResultSet> _ands; + std::vector<ResultSet> _ors; + std::vector<ResultSet> _nots; + }; + static const PreCalculated _preCalc; public: ResultSet() noexcept : _val(0u) { } - static uint32_t enumToMask(uint32_t rhs) { + static uint32_t enumToMask(uint32_t rhs) noexcept { return 1u << rhs; } - static uint32_t illegalMask() { + static uint32_t illegalMask() noexcept { return (1u << Result::enumRange); } @@ -34,14 +39,10 @@ public: _val |= enumToMask(rhs.toEnum()); } - bool hasEnum(uint32_t rhs) const { + [[nodiscard]] bool hasEnum(uint32_t rhs) const { return (_val & enumToMask(rhs)) != 0u; } - bool hasResult(const Result &rhs) const { - return hasEnum(rhs.toEnum()); - } - bool operator==(const ResultSet &rhs) const { return _val == rhs._val; } @@ -51,25 +52,25 @@ public: } // calculcate set of results emitted by document selection and operator. - ResultSet calcAnd(const ResultSet &rhs) const { - return _ands[(_val << Result::enumRange) | rhs._val]; + [[nodiscard]] ResultSet calcAnd(const ResultSet &rhs) const { + return _preCalc._ands[(_val << Result::enumRange) | rhs._val]; } // calculcate set of results emitted by document selection or operator. - ResultSet calcOr(const ResultSet &rhs) const { - return _ors[(_val << Result::enumRange) | rhs._val]; + [[nodiscard]] ResultSet calcOr(const ResultSet &rhs) const { + return _preCalc._ors[(_val << Result::enumRange) | rhs._val]; } // calculcate set of results emitted by document selection not operator. - ResultSet calcNot() const { return _nots[_val]; } + [[nodiscard]] ResultSet calcNot() const { return _preCalc._nots[_val]; } void clear() { _val = 0; } void fill() { _val = illegalMask() - 1; } static void preCalc(); private: // precalc helper methods - void pcnext(void) { ++_val; } - bool pcvalid(void) const { return _val < illegalMask(); } + void pcnext() noexcept { ++_val; } + [[nodiscard]] bool pcvalid() const noexcept { return _val < illegalMask(); } }; } |