improve filesystem loader cache and use '/' instead of DIRECTORY_SEPARATOR
authornikic <+@ni-po.com>
Tue, 14 Dec 2010 17:49:35 +0000 (18:49 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 14 Dec 2010 18:26:38 +0000 (19:26 +0100)
lib/Twig/Loader/Filesystem.php

index 98d9806..8ba22b2 100644 (file)
@@ -103,6 +103,10 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
     {
         // normalize name
         $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
+        
+        if (isset($this->cache[$name])) {
+            return $this->cache[$name];
+        }
 
         $parts = explode('/', $name);
         $level = 0;
@@ -118,13 +122,9 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
             }
         }
 
-        if (isset($this->cache[$name])) {
-            return $this->cache[$name];
-        }
-
         foreach ($this->paths as $path) {
-            if (file_exists($path.DIRECTORY_SEPARATOR.$name) && !is_dir($path.DIRECTORY_SEPARATOR.$name)) {
-                return $this->cache[$name] = $path.DIRECTORY_SEPARATOR.$name;
+            if (file_exists($path.'/'.$name) && !is_dir($path.'/'.$name)) {
+                return $this->cache[$name] = $path.'/'.$name;
             }
         }