Patchwork [1,of,9] minirst: optimize HTML table generation a bit

login
register
mail settings
Submitter Dan Villiom Podlaski Christiansen
Date March 2, 2013, 3:51 p.m.
Message ID <fabbaa250977ad337a36.1362239496@dookie.local>
Download mbox | patch
Permalink /patch/1069/
State Accepted, archived
Headers show

Comments

Dan Villiom Podlaski Christiansen - March 2, 2013, 3:51 p.m.
# HG changeset patch
# User Dan Villiom Podlaski Christiansen  <danchr@gmail.com>
# Date 1360446681 0
#      Sat Feb 09 21:51:21 2013 +0000
# Node ID fabbaa250977ad337a36b1c4cece22da94adfe4b
# Parent  13aa81e2fded35389403d2ae3a750e5af6c65dab
minirst: optimize HTML table generation a bit

avoid a couple of array copies and string interpolations
Bryan O'Sullivan - March 4, 2013, 10:20 p.m.
On Sat, Mar 2, 2013 at 7:51 AM, Dan Villiom Podlaski Christiansen <
danchr@gmail.com> wrote:

> minirst: optimize HTML table generation a bit
>
> avoid a couple of array copies and string interpolations
>

I find it helpful to document speedups when I make them (and how I measured
them, if that's not obvious), and to do so in the commit comments, as
otherwise many of the tweaks I make quickly become opaque to me. It you
were to do that here, it would be good.

Patch

diff --git a/mercurial/minirst.py b/mercurial/minirst.py
--- a/mercurial/minirst.py
+++ b/mercurial/minirst.py
@@ -559,13 +559,17 @@  def formathtml(blocks):
             out.append('<h%d>%s</h%d>\n' % (level, escape(lines[0]), level))
         elif btype == 'table':
             table = b['table']
-            t = []
+            out.append('<table>\n')
             for row in table:
-                l = []
+                out.append('<tr>')
                 for v in row:
-                    l.append('<td>%s</td>' % escape(v))
-                t.append('<tr>%s</tr>\n' % '\n'.join(l))
-            out.append('<table>\n%s</table>\n' % ''.join(t))
+                    out.append('<td>')
+                    out.append(escape(v))
+                    out.append('</td>')
+                    out.append('\n')
+                out.pop()
+                out.append('</tr>\n')
+            out.append('</table>\n')
         elif btype == 'definition':
             openlist('dl', level)
             term = escape(lines[0])