From 9b020d8f65c3d9d317ba0f98953dc260159c1d25 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 22 Dec 2020 14:45:40 -0800 Subject: [PATCH] Optimize calls to std::string::find() and friends for a single char. --- tests/pb/test_decoder.cc | 2 +- upb/bindings/lua/upbc.cc | 2 +- upbc/common.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pb/test_decoder.cc b/tests/pb/test_decoder.cc index 110dd2f9be..44478f0df7 100644 --- a/tests/pb/test_decoder.cc +++ b/tests/pb/test_decoder.cc @@ -557,7 +557,7 @@ string wrap_text(int32_t fn, const string& text) { string wrapped_text = text; size_t pos = 0; 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) { wrapped_text.replace(pos, 1, replace_with); pos += replace_with.size(); diff --git a/upb/bindings/lua/upbc.cc b/upb/bindings/lua/upbc.cc index c3988f6519..d9e1b9c647 100644 --- a/upb/bindings/lua/upbc.cc +++ b/upb/bindings/lua/upbc.cc @@ -19,7 +19,7 @@ class LuaGenerator : public protoc::CodeGenerator { }; 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) { return std::string(fname); } diff --git a/upbc/common.cc b/upbc/common.cc index c1b30a3401..cd874491cd 100644 --- a/upbc/common.cc +++ b/upbc/common.cc @@ -18,7 +18,7 @@ void AddMessages(const protobuf::Descriptor* message, } // namespace 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) { return std::string(fname); }