Patchwork D9549: simplemerge: avoid quadratic concatenation when building output text

login
register
mail settings
Submitter phabricator
Date Dec. 9, 2020, 9:28 a.m.
Message ID <differential-rev-PHID-DREV-uorm5n434dxi35hpeaip-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47846/
State Superseded
Headers show

Comments

phabricator - Dec. 9, 2020, 9:28 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9549

AFFECTED FILES
  mercurial/simplemerge.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -499,14 +499,14 @@ 
         extrakwargs[b'name_base'] = name_base
         extrakwargs[b'minimize'] = False
 
-    mergedtext = b""
+    lines = []
     for line in m3.merge_lines(
         name_a=name_a, name_b=name_b, **pycompat.strkwargs(extrakwargs)
     ):
         if opts.get('print'):
             ui.fout.write(line)
         else:
-            mergedtext += line
+            lines.append(line)
 
     # merge flags if necessary
     flags = localctx.flags()
@@ -519,6 +519,7 @@ 
         flags = b''.join(sorted(commonflags | addedflags))
 
     if not opts.get('print'):
+        mergedtext = b''.join(lines)
         localctx.write(mergedtext, flags)
 
     if m3.conflicts and not mode == b'union':