Skip to content

Commit

Permalink
src: Minor optimization for appending single character
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Nov 27, 2015
1 parent 8634937 commit c0858d8
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/HttpServer.cc
Expand Up @@ -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, "/");
}
Expand Down
6 changes: 3 additions & 3 deletions src/asio_client_session_impl.cc
Expand Up @@ -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);
}

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/asio_server_serve_mux.cc
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/h2load.cc
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/http2.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/nghttp.cc
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/shrpx_config.cc
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/shrpx_http.cc
Expand Up @@ -55,7 +55,7 @@ std::string create_via_header_value(int major, int minor) {
std::string hdrs;
hdrs += static_cast<char>(major + '0');
if (major < 2) {
hdrs += ".";
hdrs += '.';
hdrs += static_cast<char>(minor + '0');
}
hdrs += " nghttpx";
Expand Down
2 changes: 1 addition & 1 deletion src/shrpx_http2_session.cc
Expand Up @@ -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: ";
Expand Down
6 changes: 3 additions & 3 deletions src/shrpx_log.cc
Expand Up @@ -297,7 +297,7 @@ void upstream_accesslog(const std::vector<LogFragment> &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);
Expand Down Expand Up @@ -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 "
Expand Down
14 changes: 7 additions & 7 deletions src/util.cc
Expand Up @@ -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)];
}
Expand All @@ -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)];
}
Expand Down Expand Up @@ -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)];
}
Expand Down Expand Up @@ -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 += '.';
}
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit c0858d8

Please sign in to comment.