utils: hasKey(), getKeyOrEmpty(), getAll(): Take params as references

Somehow, the fact that multimap was being copyied slipped through.
This commit is contained in:
Albert S. 2021-10-09 00:10:55 +02:00
orang tua 44ade88cae
melakukan b1a8572eb6

Melihat File

@ -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 <class T, class U> bool hasKey(const std::map<T, U> &map, T key)
template <class T, class U> bool hasKey(const std::map<T, U> &map, const T &key)
{
auto k = map.find(key);
return k != map.end();
}
template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, T key)
template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, const T &key)
{
auto k = map.find(key);
if(k != map.end())
@ -36,7 +36,7 @@ template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, T key)
return U();
}
template <class T, class U> U getKeyOrEmpty(std::multimap<T, U> map, T key)
template <class T, class U> U getKeyOrEmpty(const std::multimap<T, U> &map, const T &key)
{
auto k = map.find(key);
if(k != map.end())
@ -46,7 +46,7 @@ template <class T, class U> U getKeyOrEmpty(std::multimap<T, U> map, T key)
return U();
}
template <class T, class U> std::vector<U> getAll(std::multimap<T, U> map, T key)
template <class T, class U> std::vector<U> getAll(const std::multimap<T, U> &map, const T &key)
{
std::vector<U> result;
auto range = map.equal_range(key);