[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/4] Remove assertion with side-effects



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