[gtk-doc] mkhtml2: avoid some string joins
- From: Stefan Sauer <stefkost src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-doc] mkhtml2: avoid some string joins
- Date: Fri, 2 Mar 2018 13:31:25 +0000 (UTC)
commit 554e463f7876edb466900493ba0dfeb34f929ab4
Author: Stefan Sauer <ensonic users sf net>
Date: Tue Feb 27 22:55:38 2018 +0100
mkhtml2: avoid some string joins
Just return the arrays and write them to avoid the extra string joins.
gtkdoc/mkhtml2.py | 38 +++++++++++++++++++-------------------
1 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/gtkdoc/mkhtml2.py b/gtkdoc/mkhtml2.py
index fdab883..c189479 100644
--- a/gtkdoc/mkhtml2.py
+++ b/gtkdoc/mkhtml2.py
@@ -649,12 +649,12 @@ def generate_index_nav(ctx, indexdivs):
""" % ('\n<span class="dim">|</span>\n'.join(ix_nav), generate_nav_links(ctx))
-def generate_refentry_nav(ctx, refsect1s):
- result = ["""<table class="navigation" id="top" width="100%%" cellpadding="2" cellspacing="5">
+def generate_refentry_nav(ctx, refsect1s, result):
+ result.append("""<table class="navigation" id="top" width="100%%" cellpadding="2" cellspacing="5">
<tr valign="middle">
<td width="100%%" align="left" class="shortcuts">
- <a href="#" class="shortcut">Top</a>"""
- ]
+ <a href="#" class="shortcut">Top</a>""")
+
for s in refsect1s:
# don't list TOC sections (role="xxx_proto")
if s.attrib.get('role', '').endswith("_proto"):
@@ -672,7 +672,6 @@ def generate_refentry_nav(ctx, refsect1s):
</tr>
</table>
""" % generate_nav_links(ctx))
- return ''.join(result)
def get_id(node):
@@ -694,6 +693,7 @@ def get_id(node):
# logging.warning('%s: id indexes: %s', node.filename, str(ix))
return 'id-1.' + '.'.join(ix)
+
# docbook chunks
@@ -718,7 +718,7 @@ def convert_book(ctx):
</div>
</body>
</html>""")
- return ''.join(result)
+ return result
def convert_chapter(ctx):
@@ -743,7 +743,7 @@ def convert_chapter(ctx):
</div>
</body>
</html>""")
- return ''.join(result)
+ return result
def convert_index(ctx):
@@ -755,17 +755,17 @@ def convert_index(ctx):
result = [
HTML_HEADER % (node.title + ": " + node.root.title, generate_head_links(ctx)),
generate_index_nav(ctx, indexdivs),
- ]
- result.append("""<div class="index">
+ """<div class="index">
<div class="titlepage"><h1 class="title">
<a name="%s"></a>%s</h1>
-</div>""" % (node_id, node.title))
+</div>""" % (node_id, node.title)
+ ]
for i in indexdivs:
result.extend(convert_indexdiv(ctx, i))
result.append("""</div>
</body>
</html>""")
- return ''.join(result)
+ return result
def convert_refentry(ctx):
@@ -774,9 +774,10 @@ def convert_refentry(ctx):
refsect1s = node.xml.findall('refsect1')
result = [
- HTML_HEADER % (node.title + ": " + node.root.title, generate_head_links(ctx)),
- generate_refentry_nav(ctx, refsect1s),
- """
+ HTML_HEADER % (node.title + ": " + node.root.title, generate_head_links(ctx))
+ ]
+ generate_refentry_nav(ctx, refsect1s, result)
+ result.append("""
<div class="refentry">
<a name="%s"></a>
<div class="refnamediv">
@@ -788,15 +789,14 @@ def convert_refentry(ctx):
<td class="gallery_image" valign="top" align="right"></td>
</tr></table>
</div>
-""" % (node_id, node_id, node.title, node.title)
- ]
+""" % (node_id, node_id, node.title, node.title))
for s in refsect1s:
result.extend(convert_refsect1(ctx, s))
result.append("""</div>
</body>
</html>""")
- return ''.join(result)
+ return result
# TODO(ensonic): turn into class with converters as functions and ctx as self
@@ -844,8 +844,8 @@ def convert(out_dir, files, node):
ctx.update(generate_nav_nodes(files, node))
if node.name in convert_chunks:
- # TODO(ensonic): try returning the array of string and loop over them to write them
- html.write(convert_chunks[node.name](ctx))
+ for line in convert_chunks[node.name](ctx):
+ html.write(line)
else:
logging.warning('Add converter/template for "%s"', node.name)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]