From 6882d96bf8f8b6f602c5c02842eba286f376ad62 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Tue, 19 Jan 2010 09:31:27 -0200 Subject: [PATCH] Caching charset in h(). It's save round 50% over each call by helpers. --- cake/basics.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 7a48b628b..b20854da6 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -204,13 +204,19 @@ if (!function_exists('array_combine')) { if (is_array($text)) { return array_map('h', $text); } - if (empty($charset)) { - $charset = Configure::read('App.encoding'); + + static $defaultCharset = false; + if ($defaultCharset === false) { + $defaultCharset = Configure::read('App.encoding'); + if ($defaultCharset === null) { + $defaultCharset = 'UTF-8'; + } } - if (empty($charset)) { - $charset = 'UTF-8'; + if ($charset) { + return htmlspecialchars($text, ENT_QUOTES, $charset); + } else { + return htmlspecialchars($text, ENT_QUOTES, $defaultCharset); } - return htmlspecialchars($text, ENT_QUOTES, $charset); } /**