From c891c530d36c797cebeb91d2e69af5ebfe0c8a82 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 6 May 2013 14:12:55 +0200 Subject: [PATCH] Avoid strtolower call at every twig_escape_filter call --- lib/Twig/Extension/Core.php | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index e0a6a33..8d984eb 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -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); } -- 1.7.2.5