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
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])