MDL-27120: Cache dirname transformations in progressive_parser::dirname
authorTony Levi <tony.levi@netspot.com.au>
Mon, 11 Apr 2011 06:04:02 +0000 (15:34 +0930)
committerRajesh Taneja <rajesh@moodle.com>
Tue, 29 May 2012 06:44:07 +0000 (14:44 +0800)
backup/util/xml/parser/progressive_parser.class.php

index 91bc85f..8b6df4b 100644 (file)
@@ -149,7 +149,15 @@ class progressive_parser {
      * handling parser paths, see MDL-24381
      */
     public static function dirname($path) {
-        return str_replace('\\', '/', dirname($path));
+        static $cache = array();
+
+        if (!isset($cache[$path])) {
+            if (count($cache) > 4096)
+                $cache = array();
+            $cache[$path] = str_replace('\\', '/', dirname($path));
+        }
+
+        return $cache[$path];
     }
 
 // Protected API starts here