]> source.dussan.org Git - nextcloud-server.git/commitdiff
Verify whether value is already normalized
authorLukas Reschke <lukas@owncloud.com>
Fri, 9 Jan 2015 22:34:26 +0000 (23:34 +0100)
committerLukas Reschke <lukas@owncloud.com>
Sat, 10 Jan 2015 11:12:40 +0000 (12:12 +0100)
Apparently `normalizer_normalize` is not verifying itself whether the string needs to be converted or not. Or does it at least not very performantly.

This simple change leads to a 4% performance gain on the processing of normalizeUnicode. Since this method is called quite often (i.e. for every file path) this has actually a measurable impact. For examples searches are now 200ms faster on my machine. Still not perfect but way to go.

Part of https://github.com/owncloud/core/issues/13221

lib/private/util.php

index 3178639b02e33d0dcaccb92bb8b74395729b2976..ec3640503e4ab1d11ef9eac6194eb093e924062d 100644 (file)
@@ -1274,14 +1274,17 @@ class OC_Util {
         * @return bool|string
         */
        public static function normalizeUnicode($value) {
-               $normalizedValue = normalizer_normalize($value);
+               if(Normalizer::isNormalized($value)) {
+                       return $value;
+               }
+
+               $normalizedValue = Normalizer::normalize($value);
                if ($normalizedValue === null || $normalizedValue === false) {
-                       \OC_Log::write('core', 'normalizing failed for "' . $value . '"', \OC_Log::WARN);
-               } else {
-                       $value = $normalizedValue;
+                       \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']);
+                       return $value;
                }
 
-               return $value;
+               return $normalizedValue;
        }
 
        /**