Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1345314?usp=email )

Change subject: diff: Join hunk and context fragments
......................................................................

diff: Join hunk and context fragments

Collect the header, context lines and colored hunks before joining the
complete diff. This avoids repeatedly copying the accumulated output
when several hunks are shown together on PyPy.

Preserve fragment order and apply invisible-character replacement to
the completed string as before.

Change-Id: I92462e9e329a0f6a9982e4b33f692f0d18b19fc7
---
M pywikibot/diff.py
1 file changed, 10 insertions(+), 7 deletions(-)

Approvals:
  Xqt: Verified; Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index f7a0bd2..0eced9d 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -382,17 +382,20 @@

         context_range = self._get_context_range(hunks)

-        output = (
-            f'<<aqua>>{Hunk.get_header_text(*context_range)}<<default>>\n'
-            f'{extend_context(context_range[0][0], hunks[0].a_rng[0])}'
-        )
+        diff_text = [
+            f'<<aqua>>{Hunk.get_header_text(*context_range)}<<default>>\n',
+            extend_context(context_range[0][0], hunks[0].a_rng[0]),
+        ]
         previous_hunk = None
         for hunk in hunks:
             if previous_hunk:
-                output += extend_context(previous_hunk.a_rng[1], hunk.a_rng[0])
+                diff_text.append(extend_context(previous_hunk.a_rng[1],
+                                                hunk.a_rng[0]))
             previous_hunk = hunk
-            output += hunk.diff_text
-        output += extend_context(hunks[-1].a_rng[1], context_range[0][1])
+            diff_text.append(hunk.diff_text)
+        diff_text.append(extend_context(hunks[-1].a_rng[1],
+                                        context_range[0][1]))
+        output = ''.join(diff_text)
         if self._replace_invisible:
             output = chars.replace_invisible(output)


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1345314?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I92462e9e329a0f6a9982e4b33f692f0d18b19fc7
Gerrit-Change-Number: 1345314
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to