comparison mercurial/simplemerge.py @ 46099:fd75e5c53ec3

simplemerge: avoid quadratic concatenation when building output text I haven't checked if the difference is measurable, but the new version is no less readable or idiomatic, so I don't think performance numbers are needed. Differential Revision: https://phab.mercurial-scm.org/D9549
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 08 Dec 2020 23:05:53 -0800
parents 5510e2ac213f
children a771ffc378a8
comparison
equal deleted inserted replaced
46098:5510e2ac213f 46099:fd75e5c53ec3
497 elif name_base is not None: 497 elif name_base is not None:
498 extrakwargs[b'base_marker'] = b'|||||||' 498 extrakwargs[b'base_marker'] = b'|||||||'
499 extrakwargs[b'name_base'] = name_base 499 extrakwargs[b'name_base'] = name_base
500 extrakwargs[b'minimize'] = False 500 extrakwargs[b'minimize'] = False
501 501
502 mergedtext = b"" 502 lines = []
503 for line in m3.merge_lines( 503 for line in m3.merge_lines(
504 name_a=name_a, name_b=name_b, **pycompat.strkwargs(extrakwargs) 504 name_a=name_a, name_b=name_b, **pycompat.strkwargs(extrakwargs)
505 ): 505 ):
506 if opts.get('print'): 506 if opts.get('print'):
507 ui.fout.write(line) 507 ui.fout.write(line)
508 else: 508 else:
509 mergedtext += line 509 lines.append(line)
510 510
511 # merge flags if necessary 511 # merge flags if necessary
512 flags = localctx.flags() 512 flags = localctx.flags()
513 localflags = set(pycompat.iterbytestr(flags)) 513 localflags = set(pycompat.iterbytestr(flags))
514 otherflags = set(pycompat.iterbytestr(otherctx.flags())) 514 otherflags = set(pycompat.iterbytestr(otherctx.flags()))
517 commonflags = localflags & otherflags 517 commonflags = localflags & otherflags
518 addedflags = (localflags ^ otherflags) - baseflags 518 addedflags = (localflags ^ otherflags) - baseflags
519 flags = b''.join(sorted(commonflags | addedflags)) 519 flags = b''.join(sorted(commonflags | addedflags))
520 520
521 if not opts.get('print'): 521 if not opts.get('print'):
522 mergedtext = b''.join(lines)
522 localctx.write(mergedtext, flags) 523 localctx.write(mergedtext, flags)
523 524
524 if m3.conflicts and not mode == b'union': 525 if m3.conflicts and not mode == b'union':
525 return 1 526 return 1