# HG changeset patch # User Elmar Bartel # Date 2020-04-30 13:10:05 # Node ID e58422afbc74c4a2f41929705c9ecc3936b0c4a8 # Parent a467416c493c3ab32f214b69b5d5831da24e5732 diff: re-establish linear runtime performance The previous method with sum() and list() creates a new list object for every hunk. Then sum() is used to flatten out this sequence of lists. The sum() function is not "lazy", but creates a new list object for every "+" operation and so this code had quadratic runtime behaviour. diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -2558,7 +2558,7 @@ def diff( fctx2 is not None ), b'fctx2 unexpectly None in diff hunks filtering' hunks = hunksfilterfn(fctx2, hunks) - text = b''.join(sum((list(hlines) for hrange, hlines in hunks), [])) + text = b''.join(b''.join(hlines) for hrange, hlines in hunks) if hdr and (text or len(hdr) > 1): yield b'\n'.join(hdr) + b'\n' if text: