1
0

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

Somehow, the fact that multimap was being copyied slipped through.
Este cometimento está contido em:
Albert S. 2021-10-09 00:10:55 +02:00
ascendente 44ade88cae
cometimento b1a8572eb6

Ver ficheiro

@ -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);