Make happy path (strings) faster by avoiding the cast, same perfs for the other cases

This commit is contained in:
Jordi Boggiano
2013-05-06 14:32:20 +02:00
parent 97bf5e5c44
commit d886b12637
+6 -4
View File
@@ -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