@@ -2050,6 +2050,10 @@ inline void duration_to_sec_and_usec(const T &duration, U callback) {
2050
2050
callback (static_cast <time_t >(sec), static_cast <time_t >(usec));
2051
2051
}
2052
2052
2053
+ template <size_t N> inline constexpr size_t str_len (const char (&)[N]) {
2054
+ return N - 1 ;
2055
+ }
2056
+
2053
2057
inline bool is_numeric (const std::string &str) {
2054
2058
return !str.empty () && std::all_of (str.begin (), str.end (), ::isdigit);
2055
2059
}
@@ -2209,9 +2213,9 @@ inline const char *status_message(int status) {
2209
2213
2210
2214
inline std::string get_bearer_token_auth (const Request &req) {
2211
2215
if (req.has_header (" Authorization" )) {
2212
- static std::string BearerHeaderPrefix = " Bearer " ;
2216
+ constexpr auto bearer_header_prefix_len = detail::str_len ( " Bearer " ) ;
2213
2217
return req.get_header_value (" Authorization" )
2214
- .substr (BearerHeaderPrefix. length () );
2218
+ .substr (bearer_header_prefix_len );
2215
2219
}
2216
2220
return " " ;
2217
2221
}
@@ -4646,10 +4650,8 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
4646
4650
}
4647
4651
}
4648
4652
4649
- static const std::string done_marker (" 0\r\n " );
4650
- if (!write_data (strm, done_marker.data (), done_marker.size ())) {
4651
- ok = false ;
4652
- }
4653
+ constexpr const char done_marker[] = " 0\r\n " ;
4654
+ if (!write_data (strm, done_marker, str_len (done_marker))) { ok = false ; }
4653
4655
4654
4656
// Trailer
4655
4657
if (trailer) {
@@ -4661,8 +4663,8 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
4661
4663
}
4662
4664
}
4663
4665
4664
- static const std::string crlf ( " \r\n " ) ;
4665
- if (!write_data (strm, crlf. data (), crlf. size ( ))) { ok = false ; }
4666
+ constexpr const char crlf[] = " \r\n " ;
4667
+ if (!write_data (strm, crlf, str_len (crlf ))) { ok = false ; }
4666
4668
};
4667
4669
4668
4670
data_sink.done = [&](void ) { done_with_trailer (nullptr ); };
@@ -4904,11 +4906,11 @@ class MultipartFormDataParser {
4904
4906
return false ;
4905
4907
}
4906
4908
4907
- static const std::string header_content_type = " Content-Type:" ;
4909
+ constexpr const char header_content_type[] = " Content-Type:" ;
4908
4910
4909
4911
if (start_with_case_ignore (header, header_content_type)) {
4910
4912
file_.content_type =
4911
- trim_copy (header.substr (header_content_type. size ( )));
4913
+ trim_copy (header.substr (str_len (header_content_type )));
4912
4914
} else {
4913
4915
static const std::regex re_content_disposition (
4914
4916
R"~( ^Content-Disposition:\s*form-data;\s*(.*)$)~" ,
@@ -5005,10 +5007,10 @@ class MultipartFormDataParser {
5005
5007
file_.content_type .clear ();
5006
5008
}
5007
5009
5008
- bool start_with_case_ignore (const std::string &a,
5009
- const std::string &b) const {
5010
- if (a.size () < b. size () ) { return false ; }
5011
- for (size_t i = 0 ; i < b. size () ; i++) {
5010
+ bool start_with_case_ignore (const std::string &a, const char *b) const {
5011
+ const auto b_len = strlen (b);
5012
+ if (a.size () < b_len ) { return false ; }
5013
+ for (size_t i = 0 ; i < b_len ; i++) {
5012
5014
if (case_ignore::to_lower (a[i]) != case_ignore::to_lower (b[i])) {
5013
5015
return false ;
5014
5016
}
@@ -5095,7 +5097,7 @@ class MultipartFormDataParser {
5095
5097
};
5096
5098
5097
5099
inline std::string random_string (size_t length) {
5098
- static const char data[] =
5100
+ constexpr const char data[] =
5099
5101
" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
5100
5102
5101
5103
// std::random_device might actually be deterministic on some
@@ -6094,7 +6096,7 @@ inline time_t BufferStream::duration() const { return 0; }
6094
6096
inline const std::string &BufferStream::get_buffer () const { return buffer; }
6095
6097
6096
6098
inline PathParamsMatcher::PathParamsMatcher (const std::string &pattern) {
6097
- static constexpr char marker[] = " /:" ;
6099
+ constexpr const char marker[] = " /:" ;
6098
6100
6099
6101
// One past the last ending position of a path param substring
6100
6102
std::size_t last_param_end = 0 ;
@@ -6115,7 +6117,7 @@ inline PathParamsMatcher::PathParamsMatcher(const std::string &pattern) {
6115
6117
static_fragments_.push_back (
6116
6118
pattern.substr (last_param_end, marker_pos - last_param_end + 1 ));
6117
6119
6118
- const auto param_name_start = marker_pos + 2 ;
6120
+ const auto param_name_start = marker_pos + str_len (marker) ;
6119
6121
6120
6122
auto sep_pos = pattern.find (separator, param_name_start);
6121
6123
if (sep_pos == std::string::npos) { sep_pos = pattern.length (); }
0 commit comments