summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2019-05-23 14:27:52 +0200
committerTor Egge <Tor.Egge@broadpark.no>2019-05-23 14:27:52 +0200
commit7cd0d37f36a731938ee1f95a1e34996cd2a7d5f8 (patch)
tree8e02275c2efa5129473f3a334f7f9dd9e5b17f2a /searchcore
parentaaaab3708a6faa16b0577058ffdb2908943c58ff (diff)
Allow enum values to be used directly as mask values.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/matching/handle_recorder/handle_recorder_test.cpp11
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/handlerecorder.cpp14
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/handlerecorder.h2
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp2
4 files changed, 12 insertions, 17 deletions
diff --git a/searchcore/src/tests/proton/matching/handle_recorder/handle_recorder_test.cpp b/searchcore/src/tests/proton/matching/handle_recorder/handle_recorder_test.cpp
index 62e2bb936c2..4675c09768e 100644
--- a/searchcore/src/tests/proton/matching/handle_recorder/handle_recorder_test.cpp
+++ b/searchcore/src/tests/proton/matching/handle_recorder/handle_recorder_test.cpp
@@ -13,14 +13,9 @@ using namespace proton::matching;
using HandleMap = HandleRecorder::HandleMap;
-constexpr uint32_t details_to_mask(MatchDataDetails requested_details)
-{
- return (1u << static_cast<int>(requested_details));
-}
-
-constexpr uint32_t NormalMask = details_to_mask(MatchDataDetails::Normal);
-constexpr uint32_t CheapMask = details_to_mask(MatchDataDetails::Cheap);
-constexpr uint32_t BothMask = NormalMask | CheapMask;
+constexpr MatchDataDetails NormalMask = MatchDataDetails::Normal;
+constexpr MatchDataDetails CheapMask = MatchDataDetails::Cheap;
+constexpr MatchDataDetails BothMask = static_cast<MatchDataDetails>(static_cast<int>(NormalMask) | static_cast<int>(CheapMask));
void
register_normal_handle(TermFieldHandle handle)
diff --git a/searchcore/src/vespa/searchcore/proton/matching/handlerecorder.cpp b/searchcore/src/vespa/searchcore/proton/matching/handlerecorder.cpp
index 1a2b4197bbf..ab1c8e3af49 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/handlerecorder.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/handlerecorder.cpp
@@ -4,6 +4,9 @@
#include <vespa/vespalib/stllike/asciistream.h>
#include <algorithm>
#include <cassert>
+#include <vespa/vespalib/stllike/hash_map.hpp>
+#include <vespa/vespalib/stllike/hash_map_equal.hpp>
+#include <vespa/vespalib/util/array_equal.hpp>
using search::fef::MatchDataDetails;
using search::fef::TermFieldHandle;
@@ -28,18 +31,13 @@ HandleRecorder::HandleRecorder() :
namespace {
-uint32_t details_to_mask(MatchDataDetails requested_details)
-{
- return (1u << static_cast<int>(requested_details));
-}
-
vespalib::string
handles_to_string(const HandleRecorder::HandleMap& handles, MatchDataDetails requested_details)
{
vespalib::asciistream os;
std::vector<TermFieldHandle> sorted;
for (const auto &handle : handles) {
- if ((handle.second & details_to_mask(requested_details)) != 0) {
+ if ((static_cast<int>(handle.second) & static_cast<int>(requested_details)) != 0) {
sorted.push_back(handle.first);
}
}
@@ -108,10 +106,12 @@ HandleRecorder::add(TermFieldHandle handle,
{
if (requested_details == MatchDataDetails::Normal ||
requested_details == MatchDataDetails::Cheap) {
- _handles[handle] |= details_to_mask(requested_details);
+ _handles[handle] = static_cast<MatchDataDetails>(static_cast<int>(_handles[handle]) | static_cast<int>(requested_details));
} else {
abort();
}
}
}
+
+VESPALIB_HASH_MAP_INSTANTIATE(search::fef::TermFieldHandle, search::fef::MatchDataDetails);
diff --git a/searchcore/src/vespa/searchcore/proton/matching/handlerecorder.h b/searchcore/src/vespa/searchcore/proton/matching/handlerecorder.h
index 989be463c3a..88a21fa5d7b 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/handlerecorder.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/handlerecorder.h
@@ -20,7 +20,7 @@ namespace proton::matching {
class HandleRecorder
{
public:
- using HandleMap = vespalib::hash_map<search::fef::TermFieldHandle, uint32_t>;
+ using HandleMap = vespalib::hash_map<search::fef::TermFieldHandle, search::fef::MatchDataDetails>;
class Binder : public vespalib::noncopyable {
public:
Binder(HandleRecorder & recorder);
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp
index 8c2e0e314ee..bc87ea11335 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp
@@ -32,7 +32,7 @@ bool contains_all(const HandleRecorder::HandleMap &old_map,
for (const auto &handle: new_map) {
const auto old_itr = old_map.find(handle.first);
if (old_itr == old_map.end() ||
- ((handle.second & ~(old_itr->second)) != 0)) {
+ ((static_cast<int>(handle.second) & ~static_cast<int>(old_itr->second)) != 0)) {
return false;
}
}