##// END OF EJS Templates
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer -
r2251:35fb62a3 0.9 default
parent child Browse files
Show More
@@ -9,20 +9,15 b' from demandload import demandload'
9 9 import struct, bdiff, util, mpatch
10 10 demandload(globals(), "re")
11 11
12
13 def splitnewlines(text, keepends=False):
12 def splitnewlines(text):
14 13 '''like str.splitlines, but only split on newlines.'''
15 i = 0
16 lines = []
17 while True:
18 n = text.find('\n', i)
19 if n == -1:
20 last = text[i:]
21 if last:
22 lines.append(last)
23 return lines
24 lines.append(text[i:keepends and n+1 or n])
25 i = n + 1
14 lines = [l + '\n' for l in text.split('\n')]
15 if lines:
16 if lines[-1] == '\n':
17 lines.pop()
18 else:
19 lines[-1] = lines[-1][:-1]
20 return lines
26 21
27 22 def unidiff(a, ad, b, bd, fn, r=None, text=False,
28 23 showfunc=False, ignorews=False):
@@ -33,7 +28,7 b' def unidiff(a, ad, b, bd, fn, r=None, te'
33 28 if not text and (util.binary(a) or util.binary(b)):
34 29 l = ['Binary file %s has changed\n' % fn]
35 30 elif not a:
36 b = splitnewlines(b, keepends=True)
31 b = splitnewlines(b)
37 32 if a is None:
38 33 l1 = "--- %s\t%s\n" % ("/dev/null", epoch)
39 34 else:
@@ -42,7 +37,7 b' def unidiff(a, ad, b, bd, fn, r=None, te'
42 37 l3 = "@@ -0,0 +1,%d @@\n" % len(b)
43 38 l = [l1, l2, l3] + ["+" + e for e in b]
44 39 elif not b:
45 a = splitnewlines(a, keepends=True)
40 a = splitnewlines(a)
46 41 l1 = "--- %s\t%s\n" % ("a/" + fn, ad)
47 42 if b is None:
48 43 l2 = "+++ %s\t%s\n" % ("/dev/null", epoch)
@@ -51,8 +46,8 b' def unidiff(a, ad, b, bd, fn, r=None, te'
51 46 l3 = "@@ -1,%d +0,0 @@\n" % len(a)
52 47 l = [l1, l2, l3] + ["-" + e for e in a]
53 48 else:
54 al = splitnewlines(a, keepends=True)
55 bl = splitnewlines(b, keepends=True)
49 al = splitnewlines(a)
50 bl = splitnewlines(b)
56 51 l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn,
57 52 showfunc=showfunc, ignorews=ignorews))
58 53 if not l: return ""
General Comments 0
You need to be logged in to leave comments. Login now