patch: stop using cext.diffhelpers
authorYuya Nishihara <yuya@tcha.org>
Mon, 09 Apr 2018 20:49:39 +0900
changeset 37568 f5833651ad07
parent 37567 53021c4ef0b2
child 37569 2025bf60adb2
patch: stop using cext.diffhelpers The C implementation has a couple of memory bugs, and lacks error handling which could lead to SEGV. I could fix them one by one (and I mostly finished that), but the performance gain provided by cext.diffhelper is quite low. Besides, diffhelpers.addlines() calls back Python, linereader.readline(), from the innermost loop. $ hg export -R mozilla-central 0:100 > patch $ ls -lh patch -rw-r--r-- 184M patch $ hg init repo && hg -R repo import patch --time --bypass (cext) time: real 34.970 secs (user 32.720+0.000 sys 2.230+0.000) (pure) time: real 35.950 secs (user 33.600+0.000 sys 2.330+0.000) So, let's simply use the pure Python implementation.
mercurial/patch.py
--- a/mercurial/patch.py	Mon Apr 09 20:47:43 2018 +0900
+++ b/mercurial/patch.py	Mon Apr 09 20:49:39 2018 +0900
@@ -33,20 +33,19 @@
     mail,
     mdiff,
     pathutil,
-    policy,
     pycompat,
     scmutil,
     similar,
     util,
     vfs as vfsmod,
 )
+from .pure import diffhelpers
 from .utils import (
     dateutil,
     procutil,
     stringutil,
 )
 
-diffhelpers = policy.importmod(r'diffhelpers')
 stringio = util.stringio
 
 gitre = re.compile(br'diff --git a/(.*) b/(.*)')