~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: John Arbash Meinel
  • Date: 2008-03-14 16:13:25 UTC
  • mto: This revision was merged to the branch mainline in revision 3279.
  • Revision ID: john@arbash-meinel.com-20080314161325-3cxcyg5nerrbimt2
review feedback from Robert
Use clearer variable names
profile the 'assert' section, which seemed to cost about 20% of the
time spent in find_sync_regions. (which is about 50% of merge_lines).
It seems the big overhead is actually iter_merge3(). So for now,
leave the asserts in, -O will remove them anyway.

Show diffs side-by-side

added added

removed removed

Lines of Context:
287
287
        # Do not emit regions which match, only regions which do not match
288
288
        matches = bzrlib.patiencediff.PatienceSequenceMatcher(None,
289
289
            self.base[zstart:zend], self.b[bstart:bend]).get_matching_blocks()
290
 
        zzcur = 0
291
 
        bbcur = 0
 
290
        last_base_idx = 0
 
291
        last_b_idx = 0
 
292
        last_b_idx = 0
292
293
        yielded_a = False
293
 
        for region_iz, region_ib, region_len in matches:
294
 
            conflict_z_len = region_iz - zzcur
295
 
            conflict_b_len = region_ib - bbcur
 
294
        for base_idx, b_idx, match_len in matches:
 
295
            conflict_z_len = base_idx - last_base_idx
 
296
            conflict_b_len = b_idx - last_b_idx
296
297
            if conflict_b_len == 0: # There are no lines in b which conflict,
297
298
                                    # so skip it
298
299
                pass
299
300
            else:
300
301
                if yielded_a:
301
 
                    yield ('conflict', zstart + zzcur, zstart + region_iz,
302
 
                           aend, aend, bstart + bbcur, bstart + region_ib)
 
302
                    yield ('conflict',
 
303
                           zstart + last_base_idx, zstart + base_idx,
 
304
                           aend, aend, bstart + last_b_idx, bstart + b_idx)
303
305
                else:
304
306
                    # The first conflict gets the a-range
305
307
                    yielded_a = True
306
 
                    yield ('conflict', zstart + zzcur, zstart + region_iz,
307
 
                           astart, aend, bstart + bbcur, bstart + region_ib)
308
 
            zzcur = region_iz + region_len
309
 
            bbcur = region_ib + region_len
310
 
        if zzcur != zend - zstart or bbcur != bend - bstart:
 
308
                    yield ('conflict', zstart + last_base_idx, zstart +
 
309
                    base_idx,
 
310
                           astart, aend, bstart + last_b_idx, bstart + b_idx)
 
311
            last_base_idx = base_idx + match_len
 
312
            last_b_idx = b_idx + match_len
 
313
        if last_base_idx != zend - zstart or last_b_idx != bend - bstart:
311
314
            if yielded_a:
312
 
                yield ('conflict', zstart + zzcur, zstart + region_iz,
313
 
                       aend, aend, bstart + bbcur, bstart + region_ib)
 
315
                yield ('conflict', zstart + last_base_idx, zstart + base_idx,
 
316
                       aend, aend, bstart + last_b_idx, bstart + b_idx)
314
317
            else:
315
318
                # The first conflict gets the a-range
316
319
                yielded_a = True
317
 
                yield ('conflict', zstart + zzcur, zstart + region_iz,
318
 
                       astart, aend, bstart + bbcur, bstart + region_ib)
 
320
                yield ('conflict', zstart + last_base_idx, zstart + base_idx,
 
321
                       astart, aend, bstart + last_b_idx, bstart + b_idx)
319
322
        if not yielded_a:
320
323
            yield ('conflict', zstart, zend, astart, aend, bstart, bend)
321
324
 
396
399
                aend = asub + intlen
397
400
                bend = bsub + intlen
398
401
 
399
 
                # XXX: How much overhead is involved in slicing all of these
400
 
                #      and doing an extra comparison
401
402
                assert self.base[intbase:intend] == self.a[asub:aend], \
402
403
                       (self.base[intbase:intend], self.a[asub:aend])
403
404