Optimize calls to std::string::find() and friends for a single char.

pull/13171/head
Esun Kim 4 years ago
parent 60607da72e
commit 9b020d8f65
  1. 2
      tests/pb/test_decoder.cc
  2. 2
      upb/bindings/lua/upbc.cc
  3. 2
      upbc/common.cc

@ -557,7 +557,7 @@ string wrap_text(int32_t fn, const string& text) {
string wrapped_text = text; string wrapped_text = text;
size_t pos = 0; size_t pos = 0;
string replace_with = "\n "; string replace_with = "\n ";
while ((pos = wrapped_text.find("\n", pos)) != string::npos && while ((pos = wrapped_text.find('\n', pos)) != string::npos &&
pos != wrapped_text.size() - 1) { pos != wrapped_text.size() - 1) {
wrapped_text.replace(pos, 1, replace_with); wrapped_text.replace(pos, 1, replace_with);
pos += replace_with.size(); pos += replace_with.size();

@ -19,7 +19,7 @@ class LuaGenerator : public protoc::CodeGenerator {
}; };
static std::string StripExtension(absl::string_view fname) { static std::string StripExtension(absl::string_view fname) {
size_t lastdot = fname.find_last_of("."); size_t lastdot = fname.find_last_of('.');
if (lastdot == std::string::npos) { if (lastdot == std::string::npos) {
return std::string(fname); return std::string(fname);
} }

@ -18,7 +18,7 @@ void AddMessages(const protobuf::Descriptor* message,
} // namespace } // namespace
std::string StripExtension(absl::string_view fname) { std::string StripExtension(absl::string_view fname) {
size_t lastdot = fname.find_last_of("."); size_t lastdot = fname.find_last_of('.');
if (lastdot == std::string::npos) { if (lastdot == std::string::npos) {
return std::string(fname); return std::string(fname);
} }

Loading…
Cancel
Save