abg-ir: Optimize calls to std::string::find() for a single char.

Message ID 20201215214519.2992965-1-maennich@google.com
State Committed
Headers
Series abg-ir: Optimize calls to std::string::find() for a single char. |

Commit Message

Matthias Männich Dec. 15, 2020, 9:45 p.m. UTC
  This is a common micro optimization suggested by clang-tidy to improve
string::find performance. I have not done any measurements as to how it
impacts performance for that particular piece of code, but generally
this overload is to prefer here.

	* src/abg-ir.cc (elf_symbol::get_name_and_version_from_id):
	  use character literal overload for single character string::find.
	  (parse_integral_type): Likewise.

Suggested-by: Chris Kennelly <ckennelly@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-ir.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Dodji Seketeli Jan. 12, 2021, 10:08 a.m. UTC | #1
Matthias Maennich <maennich@google.com> a écrit:

> This is a common micro optimization suggested by clang-tidy to improve
> string::find performance. I have not done any measurements as to how it
> impacts performance for that particular piece of code, but generally
> this overload is to prefer here.
>
> 	* src/abg-ir.cc (elf_symbol::get_name_and_version_from_id):
> 	  use character literal overload for single character string::find.
> 	  (parse_integral_type): Likewise.
>
> Suggested-by: Chris Kennelly <ckennelly@google.com>
> Signed-off-by: Matthias Maennich <maennich@google.com>

Applied to master, thanks!

Cheers,
  

Patch

diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index 1a4091b9370c..e11af0fd5fee 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -2031,7 +2031,7 @@  elf_symbol::get_name_and_version_from_id(const string&	id,
 {
   name.clear(), ver.clear();
 
-  string::size_type i = id.find("@");
+  string::size_type i = id.find('@');
   if (i == string::npos)
     {
       name = id;
@@ -2044,7 +2044,7 @@  elf_symbol::get_name_and_version_from_id(const string&	id,
   if (i >= id.size())
     return true;
 
-  string::size_type j = id.find("@", i);
+  string::size_type j = id.find('@', i);
   if (j == string::npos)
     j = i;
   else
@@ -12926,7 +12926,7 @@  parse_integral_type(const string&			type_name,
   while (cur_pos < len)
     {
       prev_pos = cur_pos;
-      cur_pos = input.find(" ", prev_pos);
+      cur_pos = input.find(' ', prev_pos);
       prev_word = cur_word;
       cur_word = input.substr(prev_pos, cur_pos - prev_pos);
 
@@ -12940,7 +12940,7 @@  parse_integral_type(const string&			type_name,
 	  && prev_word != "long")
 	{
 	  prev_pos = cur_pos;
-	  cur_pos = input.find(" ", prev_pos);
+	  cur_pos = input.find(' ', prev_pos);
 	  string saved_prev_word = prev_word;
 	  prev_word = cur_word;
 	  cur_word = input.substr(prev_pos, cur_pos - prev_pos);