[Reproducible-commits] [diffoscope] 03/23: Avoid concatenating many strings in hexdump_fallback

Jérémy Bobbio lunar at moszumanska.debian.org
Sat Sep 19 23:18:20 UTC 2015


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

lunar pushed a commit to branch pu/py3
in repository diffoscope.

commit 99a5678e1b9c4cbd486c4fab2ae1a57d29e982d0
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Fri Sep 18 15:35:49 2015 +0200

    Avoid concatenating many strings in hexdump_fallback
    
    Use the efficient StringIO and so avoid being quadratic.
---
 diffoscope/comparators/binary.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 8596067..0904447 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -21,6 +21,7 @@ from abc import ABCMeta, abstractmethod
 from binascii import hexlify
 from contextlib import contextmanager
 from functools import wraps
+from io import StringIO
 import os
 import os.path
 import re
@@ -48,11 +49,11 @@ def xxd(path):
 
 
 def hexdump_fallback(path):
-    hexdump = ''
+    hexdump = StringIO()
     with open(path, 'rb') as f:
         for buf in iter(lambda: f.read(32), b''):
-            hexdump += u'%s\n' % hexlify(buf).decode('us-ascii')
-    return hexdump
+            hexdump.write('%s\n' % hexlify(buf).decode('us-ascii'))
+    return hexdump.getvalue()
 
 
 def compare_binary_files(path1, path2, source=None):

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



More information about the Reproducible-commits mailing list