### 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) or
len(using) are 0, and can be significantly simplified.```
parent f6a99b2e
 ... @@ -162,25 +162,17 @@ class Differ(object): ... @@ -162,25 +162,17 @@ class Differ(object): c = cs c = cs yield c, c, c, c, c, 2 yield c, c, c, c, c, 2 def _merge_blocks(self, using, low_seq, high_seq, last_diff): def _merge_blocks(self, using): LO, HI = 1,2 LO, HI = 1,2 lowc = using[low_seq][ 0][LO] lowc = min(using[ 0][LO], using[ 0][LO]) highc = using[low_seq][-1][HI] highc = max(using[-1][HI], using[-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]) low = [] low = [] high = [] high = [] for i in (0,1): for i in (0,1): if len(using[i]): d = using[i] d = using[i] low.append(lowc - d[LO] + d[2+LO]) low.append( lowc - d[LO] + d[2+LO] ) d = using[i][-1] d = using[i][-1] high.append(highc - d[HI] + d[2+HI]) 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] ) return low, high, lowc, highc, low, high return low, high, lowc, highc, low, high def _merge_diffs(self, seq0, seq1, texts): def _merge_diffs(self, seq0, seq1, texts): ... @@ -221,8 +213,6 @@ class Differ(object): ... @@ -221,8 +213,6 @@ class Differ(object): high_diff = other_diff high_diff = other_diff high_mark = other_diff[HI] high_mark = other_diff[HI] block = self._merge_blocks( using, base_seq, high_seq, block) if len(using)==0: if len(using)==0: assert len(using)==1 assert len(using)==1 yield None, using yield None, using ... @@ -230,7 +220,7 @@ class Differ(object): ... @@ -230,7 +220,7 @@ class Differ(object): assert len(using)==1 assert len(using)==1 yield using, None yield using, None else: 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[l0:h0] == texts[l2:h2]: if h0-l0 == h2-l2 and texts[l0:h0] == texts[l2:h2]: if l1 != h1: if l1 != h1: tag = "replace" tag = "replace" ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!