src: Minor optimization for appending single character

This commit is contained in:
Tatsuhiro Tsujikawa 2015-11-28 00:03:16 +09:00
parent 863493766d
commit c0858d8c1a
11 changed files with 28 additions and 28 deletions

View File

@ -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, "/");
}

View File

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

View File

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

View File

@ -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) {

View File

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

View File

@ -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();

View File

@ -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);

View File

@ -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";

View File

@ -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: ";

View File

@ -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);
@ -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 "

View File

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