From: Armin Ronacher Date: Tue, 3 Jan 2017 00:57:12 +0000 (+0100) Subject: Small optimizations for escape branches X-Git-Tag: 2.9~30^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb0dc86a9e4a7356c0f52566070023468740cae3;p=thirdparty%2Fjinja.git Small optimizations for escape branches --- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 162e73ad..ef3da7be 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -1100,8 +1100,8 @@ class CodeGenerator(NodeVisitor): self.newline(item) close = 1 if frame.eval_ctx.volatile: - self.write('(context.eval_ctx.autoescape and' - ' escape or to_string)(') + self.write('(escape if context.eval_ctx.autoescape' + ' else to_string)(') elif frame.eval_ctx.autoescape: self.write('escape(') else: @@ -1138,8 +1138,8 @@ class CodeGenerator(NodeVisitor): self.newline(argument) close = 0 if frame.eval_ctx.volatile: - self.write('(context.eval_ctx.autoescape and' - ' escape or to_string)(') + self.write('(escape if context.eval_ctx.autoescape else' + ' to_string)(') close += 1 elif frame.eval_ctx.autoescape: self.write('escape(') @@ -1241,7 +1241,7 @@ class CodeGenerator(NodeVisitor): try: self.write(repr(node.as_const(frame.eval_ctx))) except nodes.Impossible: - self.write('(context.eval_ctx.autoescape and Markup or identity)(%r)' + self.write('(Markup if context.eval_ctx.autoescape else identity)(%r)' % node.data) def visit_Tuple(self, node, frame):