[TASK] Change if conditions in LocalizationUtility 66/34266/6
authorStefan Froemken <froemken@gmail.com>
Fri, 14 Nov 2014 18:32:29 +0000 (19:32 +0100)
committerFrank Nägler <typo3@naegler.net>
Fri, 8 May 2015 21:48:49 +0000 (23:48 +0200)
With each call to translate we call isFirstPartOfString.
This method is really fast but in case of extensionmanager
it was called over 700 times. This results in 7
milliseconds.
I have changed the if calls to improve performance

Resolves: #63026
Releases: master
Change-Id: I7beff8c49c235aa791c2d08438e5ac92bd7dc883
Reviewed-on: http://review.typo3.org/34266
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
typo3/sysext/extbase/Classes/Utility/LocalizationUtility.php

index 6b3fbd3..ce812d5 100644 (file)
@@ -79,11 +79,9 @@ class LocalizationUtility {
         * @api
         * @todo : If vsprintf gets a malformed string, it returns FALSE! Should we throw an exception there?
         */
-       static public function translate($key, $extensionName, $arguments = NULL) {
+       static public function translate($key, $extensionName = '', $arguments = NULL) {
                $value = NULL;
-               if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($key, 'LLL:')) {
-                       $value = self::translateFileReference($key);
-               } else {
+               if (!empty($key) && !empty($extensionName)) {
                        self::initializeLocalization($extensionName);
                        // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
                        if (!empty(self::$LOCAL_LANG[$extensionName][self::$languageKey][$key][0]['target'])
@@ -109,13 +107,18 @@ class LocalizationUtility {
                                        }
                                }
                        }
-                       if ($value === NULL && (!empty(self::$LOCAL_LANG[$extensionName]['default'][$key][0]['target'])
+                       if (
+                               $value === NULL && (!empty(self::$LOCAL_LANG[$extensionName]['default'][$key][0]['target'])
                                || isset(self::$LOCAL_LANG_UNSET[$extensionName]['default'][$key]))
                        ) {
                                // Default language translation for key exists
                                // No charset conversion because default is English and thereby ASCII
                                $value = self::$LOCAL_LANG[$extensionName]['default'][$key][0]['target'];
                        }
+               } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($key, 'LLL:')) {
+                       $value = self::translateFileReference($key);
+               } else {
+                       return NULL;
                }
                if (is_array($arguments) && $value !== NULL) {
                        return vsprintf($value, $arguments);