]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/utils/ftools: improve remove_from_file algorithm
authorRoss Burton <ross.burton@intel.com>
Tue, 20 Oct 2015 11:43:34 +0000 (12:43 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 28 Mar 2016 14:54:52 +0000 (15:54 +0100)
The algorithm was sub-optimal so replace it with something more elegant.

Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/utils/ftools.py

index 1bd9a30a4044d07321233af2965e0ae4fb50ba18..a7233d4ca6e9150e60abd1f38c5eeb8ea1482f26 100644 (file)
@@ -36,10 +36,11 @@ def remove_from_file(path, data):
             return
         else:
             raise
-    lines = rdata.splitlines()
-    rmdata = data.strip().splitlines()
-    for l in rmdata:
-        for c in range(0, lines.count(l)):
-            i = lines.index(l)
-            del(lines[i])
-    write_file(path, "\n".join(lines))
+
+    contents = rdata.strip().splitlines()
+    for r in data.strip().splitlines():
+        try:
+            contents.remove(r)
+        except ValueError:
+            pass
+    write_file(path, "\n".join(contents))