Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 44759:e58422afbc74 stable
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.
author | Elmar Bartel <elb_hg@leo.org> |
---|---|
date | Thu, 30 Apr 2020 15:10:05 +0200 |
parents | 9d2b2df2c2ba |
children | a56ba57c837d |
comparison
equal
deleted
inserted
replaced
44748:a467416c493c | 44759:e58422afbc74 |
---|---|
2556 # logcmdutil.getlinerangerevs() for 'hg log -L'. | 2556 # logcmdutil.getlinerangerevs() for 'hg log -L'. |
2557 assert ( | 2557 assert ( |
2558 fctx2 is not None | 2558 fctx2 is not None |
2559 ), b'fctx2 unexpectly None in diff hunks filtering' | 2559 ), b'fctx2 unexpectly None in diff hunks filtering' |
2560 hunks = hunksfilterfn(fctx2, hunks) | 2560 hunks = hunksfilterfn(fctx2, hunks) |
2561 text = b''.join(sum((list(hlines) for hrange, hlines in hunks), [])) | 2561 text = b''.join(b''.join(hlines) for hrange, hlines in hunks) |
2562 if hdr and (text or len(hdr) > 1): | 2562 if hdr and (text or len(hdr) > 1): |
2563 yield b'\n'.join(hdr) + b'\n' | 2563 yield b'\n'.join(hdr) + b'\n' |
2564 if text: | 2564 if text: |
2565 yield text | 2565 yield text |
2566 | 2566 |