From 66c116f7deb7adcd8928026aeceb536c72f5e86c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 26 Apr 2010 20:46:09 +0200 Subject: [PATCH] [ticket/9669] Add isNormalized checks for performance Since isNormalized is less expensive than normalize[1] and normalization will be applied repeatedly in most cases[2], it's more efficient to check for isNormalized. [1] http://area51.phpbb.com/phpBB/viewtopic.php?f=81&t=32718&p=208005#p208005 [2] phpBB 3.0 has a call to utf8_normalize_nfc wrapped around any multibyte request_var call. PHPBB3-9669 --- phpBB/includes/utf/utf_tools.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/utf/utf_tools.php b/phpBB/includes/utf/utf_tools.php index 8fa91a4c5b..4cc0486e91 100644 --- a/phpBB/includes/utf/utf_tools.php +++ b/phpBB/includes/utf/utf_tools.php @@ -1778,9 +1778,13 @@ else if (!is_array($strings)) { - $strings = Normalizer::normalize($strings); + if (Normalizer::isNormalized($strings)) + { + return $strings; + } + return Normalizer::normalize($strings); } - if (is_array($strings)) + else { foreach ($strings as $key => $string) { @@ -1788,11 +1792,19 @@ else { foreach ($string as $_key => $_string) { + if (Normalizer::isNormalized($strings[$key][$_key])) + { + continue; + } $strings[$key][$_key] = Normalizer::normalize($strings[$key][$_key]); } } else { + if (Normalizer::isNormalized($strings[$key])) + { + continue; + } $strings[$key] = Normalizer::normalize($strings[$key]); } }