From d886b1263798fb05deb683948071b22022c70397 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 6 May 2013 14:32:20 +0200 Subject: [PATCH] Make happy path (strings) faster by avoiding the cast, same perfs for the other cases --- lib/Twig/Extension/Core.php | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 657c3d8..c3ca51a 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -851,16 +851,18 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', return $string; } - if (!is_string($string) && !(is_object($string) && method_exists($string, '__toString'))) { - return $string; + if (!is_string($string)) { + if (is_object($string) && method_exists($string, '__toString')) { + $string = (string) $string; + } else { + return $string; + } } if (null === $charset) { $charset = $env->getCharset(); } - $string = (string) $string; - switch ($strategy) { case 'html': // see http://php.net/htmlspecialchars -- 1.7.2.5