From 40c5145453f9c83903700e31f9b393c8e9bb4bec Mon Sep 17 00:00:00 2001
From: Kai Willadsen <kai.willadsen@gmail.com>
Date: Wed, 8 Oct 2008 19:47:50 +0200
Subject: [PATCH] Refactor the diff merging loop logic

---
 diffutil.py |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/diffutil.py b/diffutil.py
index b7b5be4..6314659 100644
--- a/diffutil.py
+++ b/diffutil.py
@@ -181,34 +181,29 @@ class Differ(object):
         LO, HI = 1,2
         while len(seq0) or len(seq1):
             if len(seq0) == 0:
-                base_seq = 1
+                high_seq = 1
             elif len(seq1) == 0:
-                base_seq = 0
+                high_seq = 0
             else:
-                base_seq = seq0[0][LO] > seq1[0][LO]
+                high_seq = int(seq0[0][LO] > seq1[0][LO])
 
-            high_seq = base_seq
             high_diff = seq[high_seq].pop(0)
             high_mark = high_diff[HI]
+            other_seq = high_seq ^ 1
 
             using = [[], []]
             using[high_seq].append(high_diff)
 
-            while 1:
-                other_seq = high_seq ^ 1
-                try:
-                    other_diff = seq[other_seq][0]
-                except IndexError:
-                    break 
-                else:
-                    if high_mark < other_diff[LO]:
-                        break
+            while seq[other_seq]:
+                other_diff = seq[other_seq][0]
+                if high_mark < other_diff[LO]:
+                    break
 
                 using[other_seq].append(other_diff)
                 seq[other_seq].pop(0)
 
                 if high_mark < other_diff[HI]:
-                    high_seq ^= 1
+                    (high_seq, other_seq) = (other_seq, high_seq)
                     high_mark = other_diff[HI]
 
             if len(using[0])==0:
-- 
1.6.0.6

