From 594cdde05a408cc210a03fad69b762c3bc4eabf7 Mon Sep 17 00:00:00 2001 From: thecozies <79979276+thecozies@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:22:26 -0500 Subject: [PATCH] Use a custom hash class to enable hetereogenous lookup --- librecomp/include/librecomp/config_store.hpp | 11 ++++++----- librecomp/src/config_store.cpp | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/librecomp/include/librecomp/config_store.hpp b/librecomp/include/librecomp/config_store.hpp index 8d5400f..91ce7f7 100644 --- a/librecomp/include/librecomp/config_store.hpp +++ b/librecomp/include/librecomp/config_store.hpp @@ -7,6 +7,7 @@ #include #include +// Use a custom hash class to enable hetereogenous lookup struct string_hash { using is_transparent = void; [[nodiscard]] size_t operator()(const char *txt) const { @@ -33,12 +34,12 @@ namespace recomp { extern ConfigStore config_store; - void set_config_store_value(std::string key, config_store_value value); - void set_config_store_default_value(std::string key, config_store_value value); - void set_config_store_value_and_default(std::string key, config_store_value value, config_store_value default_value); + void set_config_store_value(std::string_view key, config_store_value value); + void set_config_store_default_value(std::string_view key, config_store_value value); + void set_config_store_value_and_default(std::string_view key, config_store_value value, config_store_value default_value); template - T get_config_store_default_value(std::string key) { + T get_config_store_default_value(std::string_view key) { std::lock_guard lock{ config_store.default_store_mutex }; auto it = config_store.default_map.find(key); if (it != config_store.default_map.end()) { @@ -54,7 +55,7 @@ namespace recomp { // Get a value from the config store, if it doesn't exist then return the default value template - T get_config_store_value(std::string key) { + T get_config_store_value(std::string_view key) { std::lock_guard lock{ config_store.store_mutex }; auto it = config_store.map.find(key); if (it != config_store.map.end()) { diff --git a/librecomp/src/config_store.cpp b/librecomp/src/config_store.cpp index 1dad201..3e96540 100644 --- a/librecomp/src/config_store.cpp +++ b/librecomp/src/config_store.cpp @@ -4,17 +4,17 @@ namespace recomp { ConfigStore config_store = {{}, {}}; -void set_config_store_value(std::string key, config_store_value value) { +void set_config_store_value(std::string_view key, config_store_value value) { std::lock_guard lock{ config_store.store_mutex }; - config_store.map[key] = value; + config_store.map[std::string{key}] = value; } -void set_config_store_default_value(std::string key, config_store_value value) { +void set_config_store_default_value(std::string_view key, config_store_value value) { std::lock_guard lock{ config_store.default_store_mutex }; - config_store.default_map[key] = value; + config_store.default_map[std::string{key}] = value; } -void set_config_store_value_and_default(std::string key, config_store_value value, config_store_value default_value) { +void set_config_store_value_and_default(std::string_view key, config_store_value value, config_store_value default_value) { set_config_store_value(key, value); set_config_store_default_value(key, default_value); }