diff mercurial/pure/bdiff.py @ 36146:29dd37a418aa

bdiff: write a native version of splitnewlines ./hg perfunidiff mercurial/manifest.py 0 --count 500 --profile before: ! wall 0.309280 comb 0.350000 user 0.290000 sys 0.060000 (best of 32) ./hg perfunidiff mercurial/manifest.py 0 --count 500 --profile after: ! wall 0.241572 comb 0.260000 user 0.240000 sys 0.020000 (best of 39) so it's about 20% faster. I hate Python. I wish we could usefully write this in Rust, but it doesn't look like that's realistic without using the cpython crate, which I'd still like to avoid. Differential Revision: https://phab.mercurial-scm.org/D1973
author Augie Fackler <augie@google.com>
date Thu, 25 Jan 2018 21:16:28 -0500
parents 5326e4ef1dab
children 8b7973d40a01
line wrap: on
line diff
--- a/mercurial/pure/bdiff.py	Mon Feb 12 16:09:31 2018 +0100
+++ b/mercurial/pure/bdiff.py	Thu Jan 25 21:16:28 2018 -0500
@@ -90,3 +90,13 @@
         text = re.sub('[ \t\r]+', ' ', text)
         text = text.replace(' \n', '\n')
     return text
+
+def splitnewlines(text):
+    '''like str.splitlines, but only split on newlines.'''
+    lines = [l + '\n' for l in text.split('\n')]
+    if lines:
+        if lines[-1] == '\n':
+            lines.pop()
+        else:
+            lines[-1] = lines[-1][:-1]
+    return lines