mirror of
https://github.com/CrowCpp/Crow.git
synced 2026-01-18 16:31:17 +01:00
Merge pull request #1131 from CrowCpp/1125-get_header_value-performs-double-lookup-on-unordered_multimap
removed double lookup on get_header_value() by map.count() and map.find()
This commit is contained in:
@@ -20,15 +20,16 @@ namespace crow // NOTE: Already documented in "crow/app.h"
|
||||
#endif
|
||||
|
||||
/// Find and return the value associated with the key. (returns an empty string if nothing is found)
|
||||
template<typename T>
|
||||
inline const std::string& get_header_value(const T& headers, const std::string& key)
|
||||
inline const std::string& get_header_value(const ci_map& headers, const std::string& key)
|
||||
{
|
||||
if (headers.count(key))
|
||||
{
|
||||
return headers.find(key)->second;
|
||||
static const std::string EMPTY;
|
||||
const auto it = headers.find(key);
|
||||
if (it != headers.end()) {
|
||||
return it->second;
|
||||
}
|
||||
else {
|
||||
return EMPTY;
|
||||
}
|
||||
static std::string empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
/// An HTTP request.
|
||||
|
||||
Reference in New Issue
Block a user