From b1a8572eb6ff01907379cbc4d038b421bd245f2d Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 9 Oct 2021 00:10:55 +0200 Subject: [PATCH] utils: hasKey(), getKeyOrEmpty(), getAll(): Take params as references Somehow, the fact that multimap was being copyied slipped through. --- utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils.h b/utils.h index 5173a4e..b49cfc2 100644 --- a/utils.h +++ b/utils.h @@ -20,13 +20,13 @@ std::string strreplace(const std::string &str, const std::string &search, const std::string html_xss(std::string_view str); std::string getenv(const std::string &key); -template bool hasKey(const std::map &map, T key) +template bool hasKey(const std::map &map, const T &key) { auto k = map.find(key); return k != map.end(); } -template U getKeyOrEmpty(const std::map &map, T key) +template U getKeyOrEmpty(const std::map &map, const T &key) { auto k = map.find(key); if(k != map.end()) @@ -36,7 +36,7 @@ template U getKeyOrEmpty(const std::map &map, T key) return U(); } -template U getKeyOrEmpty(std::multimap map, T key) +template U getKeyOrEmpty(const std::multimap &map, const T &key) { auto k = map.find(key); if(k != map.end()) @@ -46,7 +46,7 @@ template U getKeyOrEmpty(std::multimap map, T key) return U(); } -template std::vector getAll(std::multimap map, T key) +template std::vector getAll(const std::multimap &map, const T &key) { std::vector result; auto range = map.equal_range(key);