diff options
author | Henning Baldersheim <balder@oath.com> | 2019-11-12 22:06:29 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2019-11-12 22:06:29 +0000 |
commit | ad84746b242a7f20ae30fa7837584fd182a41148 (patch) | |
tree | 0cb08b1068afed398b0774c78bd9f90d157bb587 /document | |
parent | 6129472bd9b6d1b82ef5ebb7c9253adef4c20284 (diff) |
Use std::bitset instead of hash_set as there is a fixed set of bits.
Diffstat (limited to 'document')
-rw-r--r-- | document/src/vespa/document/select/resultlist.cpp | 24 | ||||
-rw-r--r-- | document/src/vespa/document/select/value.cpp | 12 |
2 files changed, 20 insertions, 16 deletions
diff --git a/document/src/vespa/document/select/resultlist.cpp b/document/src/vespa/document/select/resultlist.cpp index cd633004d26..2058e443c95 100644 --- a/document/src/vespa/document/select/resultlist.cpp +++ b/document/src/vespa/document/select/resultlist.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "resultlist.h" -#include <vespa/vespalib/stllike/hash_set.h> +#include <bitset> #include <ostream> namespace document::select { @@ -99,8 +99,7 @@ ResultList::operator&&(const ResultList& other) const { ResultList results; - // TODO: optimize - vespalib::hash_set<uint32_t> resultForNoVariables; + std::bitset<3> resultForNoVariables; for (const auto & it : _results) { for (const auto & it2 : other._results) { fieldvalue::VariableMap vars = it.first; @@ -108,15 +107,17 @@ ResultList::operator&&(const ResultList& other) const if (combineVariables(vars, it2.first)) { const Result & result = *it.second && *it2.second; if (vars.empty()) { - resultForNoVariables.insert(result.toEnum()); + resultForNoVariables.set(result.toEnum()); } else { results.add(vars, result); } } } } - for (uint32_t result : resultForNoVariables) { - results.add(fieldvalue::VariableMap(), Result::fromEnum(result)); + for (uint32_t i(0); i < resultForNoVariables.size(); i++) { + if (resultForNoVariables[i]) { + results.add(fieldvalue::VariableMap(), Result::fromEnum(i)); + } } return results; @@ -127,23 +128,24 @@ ResultList::operator||(const ResultList& other) const { ResultList results; - // TODO: optimize - vespalib::hash_set<uint32_t> resultForNoVariables; + std::bitset<3> resultForNoVariables; for (const auto & it : _results) { for (const auto & it2 : other._results) { fieldvalue::VariableMap vars = it.first; if (combineVariables(vars, it2.first)) { const Result & result = *it.second || *it2.second; if (vars.empty()) { - resultForNoVariables.insert(result.toEnum()); + resultForNoVariables.set(result.toEnum()); } else { results.add(vars, result); } } } } - for (uint32_t result : resultForNoVariables) { - results.add(fieldvalue::VariableMap(), Result::fromEnum(result)); + for (uint32_t i(0); i < resultForNoVariables.size(); i++) { + if (resultForNoVariables[i]) { + results.add(fieldvalue::VariableMap(), Result::fromEnum(i)); + } } return results; diff --git a/document/src/vespa/document/select/value.cpp b/document/src/vespa/document/select/value.cpp index 064598bf2d4..8ada946e702 100644 --- a/document/src/vespa/document/select/value.cpp +++ b/document/src/vespa/document/select/value.cpp @@ -3,7 +3,7 @@ #include "value.h" #include "operator.h" #include <vespa/document/fieldvalue/fieldvalue.h> -#include <vespa/vespalib/stllike/hash_set.h> +#include <bitset> #include <ostream> namespace document::select { @@ -409,18 +409,20 @@ ArrayValue::doCompare(const Value& value, const Predicate& cmp) const } else { ResultList results; - vespalib::hash_set<uint32_t> resultForNoVariables; + std::bitset<3> resultForNoVariables; // If comparing with other value, must match one. for (const auto & item : _values) { const Result & result = cmp(*item.second, value).combineResults(); if (item.first.empty()) { - resultForNoVariables.insert(result.toEnum()); + resultForNoVariables.set(result.toEnum()); } else { results.add(item.first, result); } } - for (uint32_t result : resultForNoVariables) { - results.add(fieldvalue::VariableMap(), Result::fromEnum(result)); + for (uint32_t i(0); i < resultForNoVariables.size(); i++) { + if (resultForNoVariables[i]) { + results.add(fieldvalue::VariableMap(), Result::fromEnum(i)); + } } return results; } |