[BUGFIX] Bring back final class name cache 21/26821/3
authorHelmut Hummel <helmut.hummel@typo3.org>
Tue, 14 Jan 2014 16:34:44 +0000 (17:34 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Wed, 15 Jan 2014 14:16:24 +0000 (15:16 +0100)
The class name needs to be determined through
a lookup in the implementation configuration
(AKA XCLASS).

This runtime cache was removed in favor of
a cache in the class loader. But this caching
behavior also changed due to the package management
API implementation.

Releases: 6.2
Resolves: #55024
Change-Id: I8dc101c0c04c88e531907fcfaf82e529af483e01
Reviewed-on: https://review.typo3.org/26821
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index 2575e5b..9da156f 100644 (file)
@@ -64,6 +64,13 @@ class GeneralUtility {
        static protected $nonSingletonInstances = array();
 
        /**
+        * Cache for makeInstance with given class name and final class names to reduce number of self::getClassName() calls
+        *
+        * @var array Given class name => final class name
+        */
+       static protected $finalClassNameCache = array();
+
+       /**
         * The application context
         *
         * @var \TYPO3\CMS\Core\Core\ApplicationContext
@@ -4207,7 +4214,12 @@ Connection: close
                if (!is_string($className) || empty($className)) {
                        throw new \InvalidArgumentException('$className must be a non empty string.', 1288965219);
                }
-               $finalClassName = self::getClassName($className);
+               if (isset(static::$finalClassNameCache[$className])) {
+                       $finalClassName = static::$finalClassNameCache[$className];
+               } else {
+                       $finalClassName = self::getClassName($className);
+                       static::$finalClassNameCache[$className] = $finalClassName;
+               }
                // Return singleton instance if it is already registered
                if (isset(self::$singletonInstances[$finalClassName])) {
                        return self::$singletonInstances[$finalClassName];
@@ -4319,7 +4331,7 @@ Connection: close
                        return FALSE;
                }
 
-               return array_key_exists($className, (array)$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'])
+               return isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][$className])
                                && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][$className])
                                && !empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][$className]['className']);
        }