Commit 9cb6407e authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Cache Mako's Template

Reuses the same Mako template as long as the template text is
the same.  This patch reduces code generation time by around
20%.

Bug: 839389
Change-Id: If8241ba70c2d572f5b6fd963f662193cc71450ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983115
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727747}
parent 0bc6b654
......@@ -13,6 +13,8 @@ _MAKO_TEMPLATE_PASS_KEY = object()
class MakoTemplate(object):
"""Represents a compiled template object."""
_mako_template_cache = {}
def __init__(self, template_text):
assert isinstance(template_text, str)
......@@ -20,8 +22,12 @@ class MakoTemplate(object):
"strict_undefined": True,
}
self._template = mako.template.Template(
text=template_text, **template_params)
template = self._mako_template_cache.get(template_text)
if template is None:
template = mako.template.Template(
text=template_text, **template_params)
self._mako_template_cache[template_text] = template
self._template = template
def mako_template(self, pass_key=None):
assert pass_key is _MAKO_TEMPLATE_PASS_KEY
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment