Skip to content

Commit 7e41d9f

Browse files
authored
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()
2 parents 2709cb0 + 5b8c0a1 commit 7e41d9f

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

include/crow/http_request.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ namespace crow // NOTE: Already documented in "crow/app.h"
2020
#endif
2121

2222
/// Find and return the value associated with the key. (returns an empty string if nothing is found)
23-
template<typename T>
24-
inline const std::string& get_header_value(const T& headers, const std::string& key)
23+
inline const std::string& get_header_value(const ci_map& headers, const std::string& key)
2524
{
26-
if (headers.count(key))
27-
{
28-
return headers.find(key)->second;
25+
static const std::string EMPTY;
26+
const auto it = headers.find(key);
27+
if (it != headers.end()) {
28+
return it->second;
29+
}
30+
else {
31+
return EMPTY;
2932
}
30-
static std::string empty;
31-
return empty;
3233
}
3334

3435
/// An HTTP request.

0 commit comments

Comments
 (0)