From 5e020f418abd08ad03cac8b5f4c29116c7cae5ab Mon Sep 17 00:00:00 2001
From: Kai Willadsen <kai.willadsen@gmail.com>
Date: Mon, 29 Sep 2008 13:44:02 +0200
Subject: [PATCH] Refactor _locate_chunk()

---
 diffutil.py |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/diffutil.py b/diffutil.py
index d0b4505..51d8a8e 100644
--- a/diffutil.py
+++ b/diffutil.py
@@ -80,14 +80,11 @@ class Differ(object):
 
     def _locate_chunk(self, whichdiffs, sequence, line):
         """Find the index of the chunk which contains line."""
-        idx = 1 + 2 * (sequence != 1)
-        i = 0
-        for c in self.diffs[whichdiffs]:
-            if line < c[idx + 1]: # Is line in chunk ?
-                break
-            else:
-                i += 1
-        return i
+        high_index = 2 + 2 * int(sequence != 1)
+        for i, c in enumerate(self.diffs[whichdiffs]):
+            if line < c[high_index]:
+                return i
+        return len(self.diffs[whichdiffs])
 
     def _change_sequence(self, which, sequence, startidx, sizechange, texts):
         diffs = self.diffs[which]
-- 
1.6.0.6

