jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1345313?usp=email )

Change subject: diff: Join colored line fragments
......................................................................

diff: Join colored line fragments

Collect tagged characters and the closing color marker in a list, then
join them once. This avoids growing a string for every character, which
can make rendering long diff lines quadratic on PyPy.

Preserve color transitions, whitespace and the whole-line shortcut.

Change-Id: I14ea7af9bc1e901caa2f1603251db53296b8febb
---
M pywikibot/diff.py
1 file changed, 4 insertions(+), 4 deletions(-)

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




diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index 0eced9d..e3954a9 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -170,7 +170,7 @@
                 return f'<<{self.colors[color]}>>{line}<<default>>'
             return line

-        colored_line = ''
+        colored_line = []
         color_closed = True
         for char, char_ref in zip_longest(
             line, line_ref.strip(), fillvalue=' '
@@ -187,12 +187,12 @@
             elif char_ref == ' ':
                 char_tagged = f'<<default>>{char}'
                 color_closed = True
-            colored_line += char_tagged
+            colored_line.append(char_tagged)

         if not color_closed:
-            colored_line += '<<default>>'
+            colored_line.append('<<default>>')

-        return colored_line
+        return ''.join(colored_line)

     def apply(self) -> Sequence[str]:
         """Turn a into b for this hunk."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1345313?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: I14ea7af9bc1e901caa2f1603251db53296b8febb
Gerrit-Change-Number: 1345313
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