[Reproducible-commits] [debbindiff] 01/01: speed up collection of stderr from Commands

Reiner Herrmann reiner at reiner-h.de
Mon Jun 22 21:09:10 UTC 2015


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

deki-guest pushed a commit to branch master
in repository debbindiff.

commit a0106838978e14165013e3a1fe5bee43cc77925d
Author: Helmut Grohne <helmut at subdivi.de>
Date:   Mon Jun 22 22:56:23 2015 +0200

    speed up collection of stderr from Commands
    
    Instead of adding strings with + which is O(n^2) in the output, use a
    StringIO that can append in O(n). This is relevant for large outputs
    such as those produced by readelf when working on foreign architecture
    binaries.
---
 debbindiff/comparators/utils.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/debbindiff/comparators/utils.py b/debbindiff/comparators/utils.py
index 66272af..d848468 100644
--- a/debbindiff/comparators/utils.py
+++ b/debbindiff/comparators/utils.py
@@ -24,6 +24,7 @@ import hashlib
 import re
 import os
 import shutil
+from StringIO import StringIO
 import subprocess
 import tempfile
 from threading import Thread
@@ -98,7 +99,7 @@ class Command(object):
         else:
             self._stdin_feeder = None
             self._process.stdin.close()
-        self._stderr = ''
+        self._stderr = StringIO()
         self._stderr_line_count = 0
         self._stderr_reader = Thread(target=self._read_stderr)
         self._stderr_reader.daemon = True
@@ -137,14 +138,14 @@ class Command(object):
         for line in iter(self._process.stderr.readline, b''):
             self._stderr_line_count += 1
             if self._stderr_line_count <= Command.MAX_STDERR_LINES:
-                self._stderr += line
+                self._stderr.write(line)
         if self._stderr_line_count > Command.MAX_STDERR_LINES:
-            self._stderr += '[ %d lines ignored ]\n' % (self._stderr_line_count - Command.MAX_STDERR_LINES)
+            self._stderr.write('[ %d lines ignored ]\n' % (self._stderr_line_count - Command.MAX_STDERR_LINES))
         self._process.stderr.close()
 
     @property
     def stderr_content(self):
-        return self._stderr
+        return self._stderr.getvalue()
 
     @property
     def stdout(self):

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



More information about the Reproducible-commits mailing list