From 109ce302888b0232ede4262abe016f6022704c85 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 29 Apr 2011 15:23:00 +0200 Subject: [PATCH] made a small speed optimization when using auto-escaping --- lib/Twig/NodeVisitor/SafeAnalysis.php | 6 ++++++ lib/Twig/Template.php | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Twig/NodeVisitor/SafeAnalysis.php b/lib/Twig/NodeVisitor/SafeAnalysis.php index 5b1bdb2..1874581 100644 --- a/lib/Twig/NodeVisitor/SafeAnalysis.php +++ b/lib/Twig/NodeVisitor/SafeAnalysis.php @@ -44,6 +44,12 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface if ($node instanceof Twig_Node_Expression_Constant) { // constants are marked safe for all $this->setSafe($node, array('all')); + } elseif ($node instanceof Twig_Node_Expression_BlockReference) { + // blocks are safe by definition + $this->setSafe($node, array('all')); + } elseif ($node instanceof Twig_Node_Expression_Parent) { + // parent block is safe by definition + $this->setSafe($node, array('all')); } elseif ($node instanceof Twig_Node_Expression_Conditional) { // intersect safeness of both operands $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3'))); diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 4484293..5a987d7 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -114,7 +114,7 @@ abstract class Twig_Template implements Twig_TemplateInterface ob_start(); $this->displayParentBlock($name, $context, $blocks); - return new Twig_Markup(ob_get_clean()); + return ob_get_clean(); } /** @@ -131,7 +131,7 @@ abstract class Twig_Template implements Twig_TemplateInterface ob_start(); $this->displayBlock($name, $context, $blocks); - return new Twig_Markup(ob_get_clean()); + return ob_get_clean(); } /** -- 1.7.2.5