public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Remove assertion with side-effects
@ 2018-01-01  0:00 Jonathan Wakely
  2018-01-01  0:00 ` Dodji Seketeli
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Jonathan Wakely @ 2018-01-01  0:00 UTC (permalink / raw)
  To: libabigail; +Cc: Jonathan Wakely

Calling assert(split_string(...)) won't do anything when NDEBUG is
defined, but the split_string call can be avoided anyway.

Since only the first result from the split string is needed, and
remove_trailing_white_spaces will trim white space anyway, the overhead
of parsing it into a vector can be avoided by using std::string::substr
directly. Additionally, calling std::string::find with a single char is
more efficient than with a string.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
---
 src/abg-tools-utils.cc | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc
index 1f25ef3..60bb773 100644
--- a/src/abg-tools-utils.cc
+++ b/src/abg-tools-utils.cc
@@ -864,24 +864,10 @@ get_dsos_provided_by_rpm(const string& rpm_path, set<string>& provided_dsos)
        line != query_output.end();
        ++line)
     {
-      vector<string> splitted;
-      string dso;
-      if (!line->empty())
-	{
-	  if (line->find("(") != string::npos)
-	    {
-	      assert(split_string(*line, "(", splitted));
-	      dso = splitted.front();
-	    }
-	  else
-	    dso = *line;
-	}
-
+      string dso = line->substr(0, line->find('('));
+      dso = remove_trailing_white_spaces(dso);
       if (!dso.empty())
-	{
-	  dso = remove_trailing_white_spaces(dso);
-	  provided_dsos.insert(dso);
-	}
+	provided_dsos.insert(dso);
     }
   return true;
 }
-- 
2.13.6

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

end of thread, other threads:[~2018-04-16 12:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-01  0:00 [PATCH 1/4] Remove assertion with side-effects Jonathan Wakely
2018-01-01  0:00 ` Dodji Seketeli
2018-01-01  0:00 ` [PATCH 2/4] Remove unused local set<string> variables Jonathan Wakely
2018-01-01  0:00   ` Dodji Seketeli
2018-01-01  0:00 ` [PATCH 3/4] Rename misleading remove_trailing_white_spaces functions Jonathan Wakely
2018-01-01  0:00   ` Dodji Seketeli
2018-01-01  0:00 ` [PATCH 4/4] Use std::string::substr instead of appending single chars Jonathan Wakely
2018-01-01  0:00   ` 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).