[meld] Refactor _locate_chunk()



commit dba9d5ee804e65519d20259ad2a2294f60bea4e5
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon Sep 29 13:44:02 2008 +0200

    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]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]