[meld] Simplifying diff chunk merging
- From: Kai Willadsen <kaiw src gnome org>
- To: svn-commits-list gnome org
- Subject: [meld] Simplifying diff chunk merging
- Date: Thu, 25 Jun 2009 07:17:39 +0000 (UTC)
commit f7c898e10aa1756ddd1cd036f8d49efcd009e864
Author: Piotr Piastucki <the_leech users berlios de>
Date: Sun Jun 7 09:11:11 2009 +0200
Simplifying diff chunk merging
In _merge_blocks(), the value of last_diff is only used when one of the
to-be-merged sequences is empty. However, in this situation, the
newly-assigned value of block in _merge_diffs() is unused. As a result,
_merge_blocks() need not be called when either len(using[0]) or
len(using[1]) are 0, and can be significantly simplified.
diffutil.py | 26 ++++++++------------------
1 files changed, 8 insertions(+), 18 deletions(-)
---
diff --git a/diffutil.py b/diffutil.py
index 7e4b487..5800b81 100644
--- a/diffutil.py
+++ b/diffutil.py
@@ -162,25 +162,17 @@ class Differ(object):
c = cs[1]
yield c[0], c[1], c[2], c[3], c[4], 2
- def _merge_blocks(self, using, low_seq, high_seq, last_diff):
+ def _merge_blocks(self, using):
LO, HI = 1,2
- lowc = using[low_seq][ 0][LO]
- highc = using[low_seq][-1][HI]
- if len(using[not low_seq]):
- lowc = min(lowc, using[not low_seq][ 0][LO])
- highc = max(highc, using[not low_seq][-1][HI])
+ lowc = min(using[0][ 0][LO], using[1][ 0][LO])
+ highc = max(using[0][-1][HI], using[1][-1][HI])
low = []
high = []
for i in (0,1):
- if len(using[i]):
- d = using[i][0]
- low.append( lowc - d[LO] + d[2+LO] )
- d = using[i][-1]
- high.append( highc - d[HI] + d[2+HI] )
- else:
- d = last_diff
- low.append( lowc - d[LO] + d[2+LO] )
- high.append( highc - d[HI] + d[2+HI] )
+ d = using[i][0]
+ low.append(lowc - d[LO] + d[2+LO])
+ d = using[i][-1]
+ high.append(highc - d[HI] + d[2+HI])
return low[0], high[0], lowc, highc, low[1], high[1]
def _merge_diffs(self, seq0, seq1, texts):
@@ -221,8 +213,6 @@ class Differ(object):
high_diff = other_diff
high_mark = other_diff[HI]
- block = self._merge_blocks( using, base_seq, high_seq, block)
-
if len(using[0])==0:
assert len(using[1])==1
yield None, using[1][0]
@@ -230,7 +220,7 @@ class Differ(object):
assert len(using[0])==1
yield using[0][0], None
else:
- l0, h0, l1, h1, l2, h2 = block
+ l0, h0, l1, h1, l2, h2 = block = self._merge_blocks(using)
if h0-l0 == h2-l2 and texts[0][l0:h0] == texts[2][l2:h2]:
if l1 != h1:
tag = "replace"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]