Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions components/core/src/clp/DictionaryReader.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef CLP_DICTIONARYREADER_HPP
#define CLP_DICTIONARYREADER_HPP

#include <iterator>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include <boost/algorithm/string.hpp>
Expand Down Expand Up @@ -34,6 +37,9 @@ class DictionaryReader {
char const* what() const noexcept override { return "DictionaryReader operation failed"; }
};

using dictionary_id_t = DictionaryIdType;
using entry_t = EntryType;

// Constructors
DictionaryReader() : m_is_open(false), m_num_segments_read_from_index(0) {
static_assert(
Expand Down Expand Up @@ -85,15 +91,15 @@ class DictionaryReader {
* @return a vector of matching entries, or an empty vector if no entry matches.
*/
std::vector<EntryType const*>
get_entry_matching_value(std::string const& search_string, bool ignore_case) const;
get_entry_matching_value(std::string_view search_string, bool ignore_case) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a test case in test-EncodedVariableInterpreter.cpp that currently casts a string_view to a string to call this method. We can now get rid of those casts.

/**
* Gets the entries that match a given wildcard string
* @param wildcard_string
* @param ignore_case
* @param entries Set in which to store found entries
*/
void get_entries_matching_wildcard_string(
std::string const& wildcard_string,
std::string_view wildcard_string,
bool ignore_case,
std::unordered_set<EntryType const*>& entries
) const;
Expand Down Expand Up @@ -235,7 +241,7 @@ DictionaryReader<DictionaryIdType, EntryType>::get_value(DictionaryIdType id) co
template <typename DictionaryIdType, typename EntryType>
std::vector<EntryType const*>
DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(
std::string const& search_string,
std::string_view search_string,
bool ignore_case
) const {
if (false == ignore_case) {
Expand All @@ -252,7 +258,11 @@ DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(
}

std::vector<EntryType const*> entries;
auto const search_string_uppercase = boost::algorithm::to_upper_copy(search_string);
std::string search_string_uppercase;
std::ignore = boost::algorithm::to_upper_copy(
std::back_inserter(search_string_uppercase),
search_string
);
for (auto const& entry : m_entries) {
if (boost::algorithm::to_upper_copy(entry.get_value()) == search_string_uppercase) {
entries.push_back(&entry);
Expand All @@ -263,7 +273,7 @@ DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value(

template <typename DictionaryIdType, typename EntryType>
void DictionaryReader<DictionaryIdType, EntryType>::get_entries_matching_wildcard_string(
std::string const& wildcard_string,
std::string_view wildcard_string,
bool ignore_case,
std::unordered_set<EntryType const*>& entries
) const {
Expand Down
8 changes: 6 additions & 2 deletions components/core/src/clp/DictionaryWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define CLP_DICTIONARYWRITER_HPP

#include <string>
#include <unordered_map>

#include <absl/container/flat_hash_map.h>

#include "ArrayBackedPosIntSet.hpp"
#include "Defs.h"
Expand Down Expand Up @@ -34,6 +35,9 @@ class DictionaryWriter {
char const* what() const noexcept override { return "DictionaryWriter operation failed"; }
};

using dictionary_id_t = DictionaryIdType;
using entry_t = EntryType;

// Constructors
DictionaryWriter() : m_is_open(false) {}

Expand Down Expand Up @@ -83,7 +87,7 @@ class DictionaryWriter {

protected:
// Types
using value_to_id_t = std::unordered_map<std::string, DictionaryIdType>;
using value_to_id_t = absl::flat_hash_map<std::string, DictionaryIdType>;

// Variables
bool m_is_open;
Expand Down
Loading
Loading