[TASK] Optimize performance of the class loader 50/24950/2
authorThomas Maroschik <tmaroschik@dfau.de>
Tue, 22 Oct 2013 07:30:10 +0000 (09:30 +0200)
committerThomas Maroschik <tmaroschik@dfau.de>
Thu, 31 Oct 2013 14:39:54 +0000 (15:39 +0100)
This change eliminates some file_exists calls and removes
an expensive regex that validated the class name.

Resolves: #53029
Releases: 6.2
Change-Id: I3d9ead0c3cdb999a540d303c8bd0709d4b827efd
Reviewed-on: https://review.typo3.org/24950
Reviewed-by: Sebastian Fischer
Reviewed-by: Wouter Wolters
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Stefan Neufeind
Tested-by: Wouter Wolters
Reviewed-by: Dmitry Dulepov
Tested-by: Dmitry Dulepov
Reviewed-by: Thomas Maroschik
Tested-by: Thomas Maroschik
typo3/sysext/core/Classes/Cache/Backend/ClassLoaderBackend.php
typo3/sysext/core/Classes/Cache/Backend/EarlyClassLoaderBackend.php
typo3/sysext/core/Classes/Core/ClassLoader.php

index c95a6ea..59c6823 100755 (executable)
@@ -179,9 +179,6 @@ class ClassLoaderBackend extends SimpleFileBackend {
         */
        public function requireOnce($entryIdentifier) {
                $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
-               if ($entryIdentifier !== basename($entryIdentifier)) {
-                       throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073036);
-               }
                return @file_exists($pathAndFilename) ? require_once $pathAndFilename : FALSE;
        }
 
index a57fb7f..66c5bab 100755 (executable)
@@ -140,7 +140,7 @@ class EarlyClassLoaderBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBack
         * @api
         */
        public function requireOnce($entryIdentifier) {
-               return require_once ($this->memoryBackend[$entryIdentifier]);
+               return isset($this->memoryBackend[$entryIdentifier]) ? require_once ($this->memoryBackend[$entryIdentifier]) : FALSE;
        }
 
        /**
index 0a4d3ed..5341b1d 100644 (file)
@@ -36,8 +36,6 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
  */
 class ClassLoader {
 
-       const VALID_CLASSNAME_PATTERN = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9\\\\_\x7f-\xff]*$/';
-
        /**
         * @var ClassAliasMap
         */
@@ -133,7 +131,7 @@ class ClassLoader {
 
                // Loads any known class via caching framework
                if ($require) {
-                       if ($this->classesCache->has($cacheEntryIdentifier) && $this->classesCache->requireOnce($cacheEntryIdentifier) !== FALSE) {
+                       if ($this->classesCache->requireOnce($cacheEntryIdentifier) !== FALSE) {
                                $cacheEntryCreated = TRUE;
                        }
                }
@@ -155,7 +153,7 @@ class ClassLoader {
                }
 
                if ($cacheEntryCreated && $require) {
-                       if ($this->classesCache->has($cacheEntryIdentifier) && $this->classesCache->requireOnce($cacheEntryIdentifier) !== FALSE) {
+                       if ($this->classesCache->requireOnce($cacheEntryIdentifier) !== FALSE) {
                                $cacheEntryCreated = TRUE;
                        }
                }
@@ -170,7 +168,7 @@ class ClassLoader {
         * @return bool
         */
        protected function isValidClassname($className) {
-               return (bool) preg_match(self::VALID_CLASSNAME_PATTERN, $className);
+               return strpos($className, ' ') === FALSE;
        }
 
        /**