Use single-character version of string find() (performance-faster-string-find)

This commit is contained in:
Tim Wojtulewicz 2020-02-03 11:19:37 -05:00
parent 95d2af4501
commit c32566420a
8 changed files with 10 additions and 10 deletions

View file

@ -402,7 +402,7 @@ void HTTP_Entity::SubmitHeader(mime::MIME_Header* h)
return;
}
size_t p = byte_range.find("/");
size_t p = byte_range.find('/');
if ( p == string::npos )
{
http_message->Weird("HTTP_content_range_cannot_parse");
@ -412,7 +412,7 @@ void HTTP_Entity::SubmitHeader(mime::MIME_Header* h)
string byte_range_resp_spec = byte_range.substr(0, p);
string instance_length_str = byte_range.substr(p + 1);
p = byte_range_resp_spec.find("-");
p = byte_range_resp_spec.find('-');
if ( p == string::npos )
{
http_message->Weird("HTTP_content_range_cannot_parse");

View file

@ -34,7 +34,7 @@ void IRC_Analyzer::Done()
inline void IRC_Analyzer::SkipLeadingWhitespace(string& str)
{
const auto first_char = str.find_first_not_of(" ");
const auto first_char = str.find_first_not_of(' ');
if ( first_char == string::npos )
str = "";
else

View file

@ -13,7 +13,7 @@ refine connection XMPP_Conn += {
string token = std_str(name);
// Result will either be text after ":" or original string; this discards the namespace
string token_no_ns = std_str(name);
auto offset = token_no_ns.find(":");
auto offset = token_no_ns.find(':');
if ( offset != std::string::npos && token_no_ns.length() > offset + 1 )
token_no_ns = token_no_ns.substr(offset + 1);

View file

@ -130,7 +130,7 @@ bool Ascii::OpenFile()
if ( fname.front() != '/' && ! path_prefix.empty() )
{
string path = path_prefix;
std::size_t last = path.find_last_not_of("/");
std::size_t last = path.find_last_not_of('/');
if ( last == string::npos ) // Nothing but slashes -- weird but ok...
path = "/";

View file

@ -111,7 +111,7 @@ bool Binary::DoInit(const ReaderInfo& info, int num_fields,
if ( fname.front() != '/' && ! path_prefix.empty() )
{
string path = path_prefix;
std::size_t last = path.find_last_not_of("/");
std::size_t last = path.find_last_not_of('/');
if ( last == string::npos ) // Nothing but slashes -- weird but ok...
path = "/";

View file

@ -210,7 +210,7 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p
{
const char *text = (const char*) sqlite3_column_text(st, pos);
string s(text, sqlite3_column_bytes(st, pos));
int pos = s.find("/");
int pos = s.find('/');
int width = atoi(s.substr(pos+1).c_str());
string addr = s.substr(0, pos);

View file

@ -48,7 +48,7 @@ void Manager::SearchDynamicPlugins(const std::string& dir)
if ( dir.empty() )
return;
if ( dir.find(":") != string::npos )
if ( dir.find(':') != string::npos )
{
// Split at ":".
std::stringstream s(dir);
@ -492,7 +492,7 @@ Plugin* Manager::LookupPluginByPath(std::string_view _path)
if ( i != plugins_by_path.end() )
return i->second;
auto j = path.rfind("/");
auto j = path.rfind('/');
if ( j == std::string::npos )
break;

View file

@ -300,7 +300,7 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag
case TYPE_SUBNET:
{
string unescaped = strstrip(get_unescaped_string(s));
size_t pos = unescaped.find("/");
size_t pos = unescaped.find('/');
if ( pos == unescaped.npos )
{
GetThread()->Warning(GetThread()->Fmt("Invalid value for subnet: %s", start));