src: apply clang-tidy performance-faster-string-find

PR-URL: https://github.com/nodejs/node/pull/26812
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
gengjiawen 2019-03-20 20:55:22 +08:00 committed by Refael Ackermann
parent 7d201c4e70
commit 86e0296631
2 changed files with 3 additions and 3 deletions

View File

@ -156,10 +156,10 @@ static void generate_accept_string(const std::string& client_key,
} }
static std::string TrimPort(const std::string& host) { static std::string TrimPort(const std::string& host) {
size_t last_colon_pos = host.rfind(":"); size_t last_colon_pos = host.rfind(':');
if (last_colon_pos == std::string::npos) if (last_colon_pos == std::string::npos)
return host; return host;
size_t bracket = host.rfind("]"); size_t bracket = host.rfind(']');
if (bracket == std::string::npos || last_colon_pos > bracket) if (bracket == std::string::npos || last_colon_pos > bracket)
return host.substr(0, last_colon_pos); return host.substr(0, last_colon_pos);
return host; return host;

View File

@ -507,7 +507,7 @@ static void PrintSystemInformation(JSONWriter* writer) {
WideCharToMultiByte( WideCharToMultiByte(
CP_UTF8, 0, lpszVariable, -1, str, size, nullptr, nullptr); CP_UTF8, 0, lpszVariable, -1, str, size, nullptr, nullptr);
std::string env(str); std::string env(str);
int sep = env.rfind("="); int sep = env.rfind('=');
std::string key = env.substr(0, sep); std::string key = env.substr(0, sep);
std::string value = env.substr(sep + 1); std::string value = env.substr(sep + 1);
writer->json_keyvalue(key, value); writer->json_keyvalue(key, value);