[diffoscope] 01/01: presenters/text: Avoid unnecessary splitting and interpolating for a ~20X optimisation in writing --text output.

Chris Lamb chris at chris-lamb.co.uk
Mon Dec 26 21:07:28 CET 2016


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit bfa7ac8797c5aeb6a4d6f91d6805711be9898408
Author: Chris Lamb <lamby at debian.org>
Date:   Mon Dec 26 20:06:22 2016 +0000

    presenters/text: Avoid unnecessary splitting and interpolating for a ~20X optimisation in writing --text output.
    
    On my machine this speeds up text output of two FreeBSD base images
    (~100MB --text output) from 10 seconds to 0.5 seconds, but this
    optimisation will likely yield even greater speedups on larger inputs.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/presenters/text.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/diffoscope/presenters/text.py b/diffoscope/presenters/text.py
index c56e660..9a5d113 100644
--- a/diffoscope/presenters/text.py
+++ b/diffoscope/presenters/text.py
@@ -34,8 +34,9 @@ def print_difference(difference, print_func, color=False):
             diff_output = color_unified_diff(difference.unified_diff)
         else:
             diff_output = difference.unified_diff
-        for line in diff_output.splitlines():
-            print_func(u"│ %s" % line)
+        # As an optimisation, output as much as possible in one go to avoid
+        # unnecessary splitting, interpolating, etc.
+        print_func(diff_output.replace('\n', '│ \n'))
 
 def print_details(difference, print_func, color=False):
     if not difference.details:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list