Avoid strtolower call at every twig_escape_filter call
authorJordi Boggiano <j.boggiano@seld.be>
Mon, 6 May 2013 12:12:55 +0000 (14:12 +0200)
committerJordi Boggiano <j.boggiano@seld.be>
Mon, 6 May 2013 12:12:55 +0000 (14:12 +0200)
lib/Twig/Extension/Core.php

index e0a6a33..8d984eb 100644 (file)
@@ -885,7 +885,14 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
                 'iso8859-5' => true, 'iso-8859-5' => true, 'macroman' => true,
             );
 
+            if (isset($htmlspecialcharsCharsets[$charset])) {
+                return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
+            }
+
             if (isset($htmlspecialcharsCharsets[strtolower($charset)])) {
+                // cache the uppercase variant for future iterations
+                $htmlspecialcharsCharsets[$charset] = true;
+
                 return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
             }