From: Jordi Boggiano Date: Mon, 6 May 2013 12:32:20 +0000 (+0200) Subject: Make happy path (strings) faster by avoiding the cast, same perfs for the other cases X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d886b1263798fb05deb683948071b22022c70397;p=web%2Fkonrad%2Ftwig.git Make happy path (strings) faster by avoiding the cast, same perfs for the other cases --- 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