public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] abg-ir: Optimize calls to std::string::find() for a single char.
@ 2020-12-15 21:45 Matthias Maennich
  2021-01-12 10:08 ` Dodji Seketeli
  0 siblings, 1 reply; 2+ messages in thread
From: Matthias Maennich @ 2020-12-15 21:45 UTC (permalink / raw)
  To: libabigail; +Cc: dodji, gprocida, kernel-team, maennich, Chris Kennelly

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(-)

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);
-- 
2.29.2.684.gfbc64c5ab5-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] abg-ir: Optimize calls to std::string::find() for a single char.
  2020-12-15 21:45 [PATCH] abg-ir: Optimize calls to std::string::find() for a single char Matthias Maennich
@ 2021-01-12 10:08 ` Dodji Seketeli
  0 siblings, 0 replies; 2+ messages in thread
From: Dodji Seketeli @ 2021-01-12 10:08 UTC (permalink / raw)
  To: Matthias Maennich; +Cc: libabigail, gprocida, kernel-team, Chris Kennelly

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,

-- 
		Dodji

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-12 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 21:45 [PATCH] abg-ir: Optimize calls to std::string::find() for a single char Matthias Maennich
2021-01-12 10:08 ` Dodji Seketeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).