changeset 445:d8d86debea81

performance: Only use Jinja2 for rendering text if necessary.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 30 Jun 2015 21:39:20 -0700
parents 1359b2b0cc73
children 4cdf6c2157a0
files piecrust/templating/jinjaengine.py
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/templating/jinjaengine.py	Mon Jun 29 18:12:31 2015 -0700
+++ b/piecrust/templating/jinjaengine.py	Tue Jun 30 21:39:20 2015 -0700
@@ -36,6 +36,19 @@
     def renderString(self, txt, data, filename=None):
         self._ensureLoaded()
 
+        offset = 0
+        do_render = False
+        index = txt.find('{')
+        while index >= 0:
+            ch = txt[index + 1]
+            if ch == '{' or ch == '%':
+                do_render = True
+                break
+            index = txt.find('{', offset + 1)
+
+        if not do_render:
+            return txt
+
         try:
             tpl = self.env.from_string(txt)
         except TemplateSyntaxError as tse: