diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-11-10 20:02:54 +0100 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-11-11 20:50:10 +0100 |
commit | 6a789f0afcc5894a81e3f56e11883f1446d46e7b (patch) | |
tree | 2ad76627f7656dd1cfc7c635def0b54a80b0c3cb /decoder/pdtest | |
parent | 7d97c1424a7b39ccdf37128d66fb6632baf8f523 (diff) | |
download | sigrok-test-6a789f0afcc5894a81e3f56e11883f1446d46e7b.tar.gz sigrok-test-6a789f0afcc5894a81e3f56e11883f1446d46e7b.zip |
pdtest: use less expensive Python routine to get text differences
Python ships with a difflib(3) module which is used in the pdtest(1)
utility. The Differ.compare() routine is rather expensive, especially
when the set of input text becomes "large" (a few thousand lines). Use
the less expensive unified_diff() routine instead which does not suffer
from that cost. From the sigrok-test perspective the resulting data is
as usable.
Diffstat (limited to 'decoder/pdtest')
-rwxr-xr-x | decoder/pdtest | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/decoder/pdtest b/decoder/pdtest index e3509b9..5948325 100755 --- a/decoder/pdtest +++ b/decoder/pdtest @@ -24,7 +24,7 @@ import re from getopt import getopt from tempfile import mkstemp from subprocess import Popen, PIPE -from difflib import Differ +from difflib import unified_diff from hashlib import md5 from shutil import copy @@ -236,12 +236,9 @@ def get_tests(testnames): def diff_text(f1, f2): t1 = open(f1).readlines() t2 = open(f2).readlines() - diff = [] - d = Differ() - for line in d.compare(t1, t2): - if line[:2] in ('- ', '+ '): - diff.append(line.strip()) - + diff = list(unified_diff(t1, t2)) + diff = diff[2:] # Strip two from/to filename lines with "+++"/"---". + diff = [d.strip() for d in diff if d[0] in ('+', '-')] return diff |