[Pkg-bazaar-commits] ./bzr/unstable r839: - avoid copying string lists when handling unmatched regions

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:21:13 UTC 2009


------------------------------------------------------------
revno: 839
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Wed 2005-07-06 14:09:02 +1000
message:
  - avoid copying string lists when handling unmatched regions
modified:
  bzrlib/merge3.py
-------------- next part --------------
=== modified file 'bzrlib/merge3.py'
--- a/bzrlib/merge3.py	2005-07-06 01:04:08 +0000
+++ b/bzrlib/merge3.py	2005-07-06 04:09:02 +0000
@@ -43,6 +43,19 @@
         return None
 
 
+def compare_range(a, astart, aend, b, bstart, bend):
+    """Compare a[astart:aend] == b[bstart:bend], without slicing.
+    """
+    if (aend-astart) != (bend-bstart):
+        return False
+    for ia, ib in zip(xrange(astart, aend), xrange(bstart, bend)):
+        if a[ia] != b[ib]:
+            return False
+    else:
+        return True
+        
+
+
 
 class Merge3(object):
     """3-way merge of texts.
@@ -214,17 +227,13 @@
             #print 'unmatched a=%d, b=%d' % (len_a, len_b)
 
             if len_a or len_b:
-                lines_base = self.base[iz:zmatch]
-                lines_a = self.a[ia:amatch]
-                lines_b = self.b[ib:bmatch]
-
-                # we check the len just as a shortcut
-                equal_a = (len_a == len_base
-                           and lines_a == lines_base)
-                equal_b = (len_b == len_base
-                           and lines_b == lines_base)
-                same = (len_a == len_b
-                        and lines_a == lines_b)
+                # try to avoid actually slicing the lists
+                equal_a = compare_range(self.a, ia, amatch,
+                                        self.base, iz, zmatch)
+                equal_b = compare_range(self.b, ib, bmatch,
+                                        self.base, iz, zmatch)
+                same = compare_range(self.a, ia, amatch,
+                                     self.b, ib, bmatch)
 
                 if same:
                     yield 'same', ia, amatch
@@ -235,7 +244,7 @@
                 elif not equal_a and not equal_b:
                     yield 'conflict', iz, zmatch, ia, amatch, ib, bmatch
                 else:
-                    assert 0
+                    raise AssertionError("can't handle a=b=base but unmatched")
 
                 ia = amatch
                 ib = bmatch



More information about the Pkg-bazaar-commits mailing list