[diffoscope] 01/01: Optimize the common case of feeders. (Closes: #863879)

Chris Lamb chris at chris-lamb.co.uk
Wed Jan 3 21:18:34 CET 2018


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

lamby pushed a commit to branch master
in repository diffoscope.

commit 11370138e95176ba083bb0ad0876be7c5f4b568d
Author: Daniel Shahaf <danielsh at apache.org>
Date:   Wed Jan 3 20:15:16 2018 +0000

    Optimize the common case of feeders. (Closes: #863879)
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/feeders.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/diffoscope/feeders.py b/diffoscope/feeders.py
index c8a84af..019ece5 100644
--- a/diffoscope/feeders.py
+++ b/diffoscope/feeders.py
@@ -30,7 +30,7 @@ logger = logging.getLogger(__name__)
 DIFF_CHUNK = 4096
 
 
-def from_raw_reader(in_file, filter=lambda buf: buf):
+def from_raw_reader(in_file, filter=None):
     def feeder(out_file):
         max_lines = Config().max_diff_input_lines
         end_nl = False
@@ -44,7 +44,7 @@ def from_raw_reader(in_file, filter=lambda buf: buf):
 
         for buf in in_file:
             line_count += 1
-            out = filter(buf)
+            out = buf if filter is None else filter(buf)
 
             if h is not None:
                 h.update(out)
@@ -68,9 +68,13 @@ def from_raw_reader(in_file, filter=lambda buf: buf):
     return feeder
 
 
-def from_text_reader(in_file, filter=lambda text_buf: text_buf):
-    def encoding_filter(text_buf):
-        return filter(text_buf).encode('utf-8')
+def from_text_reader(in_file, filter=None):
+    if filter is None:
+        def encoding_filter(text_buf):
+            return text_buf.encode('utf-8')
+    else:
+        def encoding_filter(text_buf):
+            return filter(text_buf).encode('utf-8')
     return from_raw_reader(in_file, encoding_filter)
 
 

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


More information about the diffoscope mailing list