From c0858d8c1af4804ef8f3412d82c01af074dada94 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 28 Nov 2015 00:03:16 +0900 Subject: [PATCH] src: Minor optimization for appending single character --- src/HttpServer.cc | 2 +- src/asio_client_session_impl.cc | 6 +++--- src/asio_server_serve_mux.cc | 2 +- src/h2load.cc | 4 ++-- src/http2.cc | 12 ++++++------ src/nghttp.cc | 4 ++-- src/shrpx_config.cc | 2 +- src/shrpx_http.cc | 2 +- src/shrpx_http2_session.cc | 2 +- src/shrpx_log.cc | 6 +++--- src/util.cc | 14 +++++++------- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index ded5b6fd..93f8c917 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -1228,7 +1228,7 @@ void prepare_response(Stream *stream, Http2Handler *hd, close(file); if (query_pos == std::string::npos) { - reqpath += "/"; + reqpath += '/'; } else { reqpath.insert(query_pos, "/"); } diff --git a/src/asio_client_session_impl.cc b/src/asio_client_session_impl.cc index 33f21137..3be7b20d 100644 --- a/src/asio_client_session_impl.cc +++ b/src/asio_client_session_impl.cc @@ -420,10 +420,10 @@ const request *session_impl::submit(boost::system::error_code &ec, if (util::ipv6_numeric_addr(uref.host.c_str())) { uref.host = "[" + uref.host; - uref.host += "]"; + uref.host += ']'; } if (u.field_set & (1 << UF_PORT)) { - uref.host += ":"; + uref.host += ':'; uref.host += util::utos(u.port); } @@ -435,7 +435,7 @@ const request *session_impl::submit(boost::system::error_code &ec, auto path = uref.raw_path; if (u.field_set & (1 << UF_QUERY)) { - path += "?"; + path += '?'; path += uref.raw_query; } diff --git a/src/asio_server_serve_mux.cc b/src/asio_server_serve_mux.cc index 829568ba..d2b43925 100644 --- a/src/asio_server_serve_mux.cc +++ b/src/asio_server_serve_mux.cc @@ -83,7 +83,7 @@ request_cb serve_mux::handler(request_impl &req) const { auto new_uri = util::percent_encode_path(clean_path); auto &uref = req.uri(); if (!uref.raw_query.empty()) { - new_uri += "?"; + new_uri += '?'; new_uri += uref.raw_query; } diff --git a/src/h2load.cc b/src/h2load.cc index 26d75ac6..c868906a 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -1177,7 +1177,7 @@ std::string get_reqline(const char *uri, const http_parser_url &u) { } if (util::has_uri_field(u, UF_QUERY)) { - reqline += "?"; + reqline += '?'; reqline += util::get_uri_field(uri, u, UF_QUERY); } @@ -1954,7 +1954,7 @@ int main(int argc, char **argv) { for (auto &req : reqlines) { // For HTTP/1.1 auto h1req = (*method_it).value; - h1req += " "; + h1req += ' '; h1req += req; h1req += " HTTP/1.1\r\n"; for (auto &nv : shared_nva) { diff --git a/src/http2.cc b/src/http2.cc index acac147a..6faaeddf 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -471,12 +471,12 @@ std::string rewrite_location_uri(const std::string &uri, } if (u.field_set & (1 << UF_QUERY)) { field = &u.field_data[UF_QUERY]; - res += "?"; + res += '?'; res.append(&uri[field->off], field->len); } if (u.field_set & (1 << UF_FRAGMENT)) { field = &u.field_data[UF_FRAGMENT]; - res += "#"; + res += '#'; res.append(&uri[field->off], field->len); } return res; @@ -1185,12 +1185,12 @@ std::string path_join(const char *base_path, size_t base_pathlen, } if (rel_querylen == 0) { if (base_querylen) { - res += "?"; + res += '?'; res.append(base_query, base_querylen); } return res; } - res += "?"; + res += '?'; res.append(rel_query, rel_querylen); return res; } @@ -1242,7 +1242,7 @@ std::string path_join(const char *base_path, size_t base_pathlen, ; } if (rel_querylen) { - res += "?"; + res += '?'; res.append(rel_query, rel_querylen); } return res; @@ -1500,7 +1500,7 @@ int construct_push_component(std::string &scheme, std::string &authority, if (u.field_set & (1 << UF_HOST)) { http2::copy_url_component(authority, &u, UF_HOST, uri); if (u.field_set & (1 << UF_PORT)) { - authority += ":"; + authority += ':'; authority += util::utos(u.port); } } diff --git a/src/nghttp.cc b/src/nghttp.cc index e48d6592..057eac01 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -168,7 +168,7 @@ std::string Request::make_reqpath() const { ? util::get_uri_field(uri.c_str(), u, UF_PATH) : "/"; if (util::has_uri_field(u, UF_QUERY)) { - path += "?"; + path += '?'; path.append(uri.c_str() + u.field_data[UF_QUERY].off, u.field_data[UF_QUERY].len); } @@ -828,7 +828,7 @@ int HttpClient::on_upgrade_connect() { reqvec[0]->method = "GET"; } else { req = (*meth).value; - req += " "; + req += ' '; reqvec[0]->method = (*meth).value; } req += reqvec[0]->make_reqpath(); diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index a2e35abf..b379b7ac 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -596,7 +596,7 @@ void parse_mapping(const DownstreamAddr &addr, const char *src) { // This effectively makes empty pattern to "/". pattern.assign(raw_pattern.first, raw_pattern.second); util::inp_strlower(pattern); - pattern += "/"; + pattern += '/'; } else { pattern.assign(raw_pattern.first, slash); util::inp_strlower(pattern); diff --git a/src/shrpx_http.cc b/src/shrpx_http.cc index c3f1aa7b..5f2f4b9e 100644 --- a/src/shrpx_http.cc +++ b/src/shrpx_http.cc @@ -55,7 +55,7 @@ std::string create_via_header_value(int major, int minor) { std::string hdrs; hdrs += static_cast(major + '0'); if (major < 2) { - hdrs += "."; + hdrs += '.'; hdrs += static_cast(minor + '0'); } hdrs += " nghttpx"; diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 508ccd34..dd6ed02d 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -520,7 +520,7 @@ int Http2Session::downstream_connect_proxy() { std::string req = "CONNECT "; req += downstream_addr.hostport.get(); if (downstream_addr.port == 80 || downstream_addr.port == 443) { - req += ":"; + req += ':'; req += util::utos(downstream_addr.port); } req += " HTTP/1.1\r\nHost: "; diff --git a/src/shrpx_log.cc b/src/shrpx_log.cc index 59095b51..6055f3e9 100644 --- a/src/shrpx_log.cc +++ b/src/shrpx_log.cc @@ -297,7 +297,7 @@ void upstream_accesslog(const std::vector &lfv, if (frac.size() < 3) { frac = std::string(3 - frac.size(), '0') + frac; } - sec += "."; + sec += '.'; sec += frac; std::tie(p, avail) = copy(sec, avail, p); @@ -415,12 +415,12 @@ void log_chld(pid_t pid, int rstatus, const char *msg) { auto s = strsignal(sig); if (s) { signalstr += s; - signalstr += "("; + signalstr += '('; } else { signalstr += "UNKNOWN("; } signalstr += util::utos(sig); - signalstr += ")"; + signalstr += ')'; } LOG(NOTICE) << msg << ": [" << pid << "] exited " diff --git a/src/util.cc b/src/util.cc index a4897868..5f0a7276 100644 --- a/src/util.cc +++ b/src/util.cc @@ -89,7 +89,7 @@ std::string percentEncode(const unsigned char *target, size_t len) { if (inRFC3986UnreservedChars(c)) { dest += c; } else { - dest += "%"; + dest += '%'; dest += UPPER_XDIGITS[c >> 4]; dest += UPPER_XDIGITS[(c & 0x0f)]; } @@ -110,7 +110,7 @@ std::string percent_encode_path(const std::string &s) { continue; } - dest += "%"; + dest += '%'; dest += UPPER_XDIGITS[(c >> 4) & 0x0f]; dest += UPPER_XDIGITS[(c & 0x0f)]; } @@ -141,7 +141,7 @@ std::string percent_encode_token(const std::string &target) { if (c != '%' && in_token(c)) { dest += c; } else { - dest += "%"; + dest += '%'; dest += UPPER_XDIGITS[c >> 4]; dest += UPPER_XDIGITS[(c & 0x0f)]; } @@ -712,7 +712,7 @@ std::string ascii_dump(const uint8_t *data, size_t len) { if (c >= 0x20 && c < 0x7f) { res += c; } else { - res += "."; + res += '.'; } } @@ -1103,17 +1103,17 @@ std::string make_hostport(const char *host, uint16_t port) { std::string hostport; if (ipv6) { - hostport += "["; + hostport += '['; } hostport += host; if (ipv6) { - hostport += "]"; + hostport += ']'; } if (port != 80 && port != 443) { - hostport += ":"; + hostport += ':'; hostport += utos(port); }