Index: lib/ezutils/classes/ezini.php
===================================================================
--- lib/ezutils/classes/ezini.php	(revision 21851)
+++ lib/ezutils/classes/ezini.php	(working copy)
@@ -78,6 +78,10 @@
 {
     const CACHE_CODE_DATE = 1043407542;
     const DEBUG_INTERNALS = false;
+    
+    // set EZ_INI_PERFORMANCE_MODE global to true to improve performance
+    // $GLOBALS['EZ_INI_PERFORMANCE_MODE'] = true;
+    static protected $performanceMode = null;
 
     /*!
       Initialization of object;
@@ -106,6 +110,11 @@
         $this->DirectAccess = $directAccess;
         $this->UseLocalOverrides = $useLocalOverrides;
         $this->AddArrayDefinition = $addArrayDefinition;
+        
+        if ( self::$performanceMode === null )
+        {
+            self::$performanceMode = isset( $GLOBALS['EZ_INI_PERFORMANCE_MODE'] ) && $GLOBALS['EZ_INI_PERFORMANCE_MODE'];
+        }
 
         if ( $this->UseLocalOverrides == true )
         {
@@ -234,10 +243,10 @@
             $rootDir = "settings";
         if ( file_exists( $rootDir . '/' . $fileName ) )
             return true;
-        else if ( file_exists( $rootDir . '/' . $fileName . '.append' ) )
-            return true;
         else if ( file_exists( $rootDir . '/' . $fileName . '.append.php' ) )
             return true;
+        else if ( file_exists( $rootDir . '/' . $fileName . '.append' ) )
+            return true;
         return false;
     }
 
@@ -290,7 +299,7 @@
 
         $inputFiles = array();
 
-        if ( $this->FileName == 'override.ini' )
+        if ( $this->FileName === 'override.ini' )
         {
             eZExtension::prependExtensionSiteAccesses( false, $this, true, false, false );
         }
@@ -299,10 +308,10 @@
             $inputFiles[] = $iniFile;
 
         // try the same file name with '.append.php' replace with '.append'
-        if ( preg_match('/^(.+.append).php$/i', $iniFile, $matches ) && file_exists( $matches[1] ) )
+        if ( strpos($iniFile, '.append.php') !== false && preg_match('/^(.+.append).php$/i', $iniFile, $matches ) && file_exists( $matches[1] ) )
             $inputFiles[] = $matches[1];
 
-        if ( file_exists ( $iniFile . '.php' ) )
+        if ( strpos($iniFile, '.php') === false && file_exists ( $iniFile . '.php' ) )
             $inputFiles[] = $iniFile . '.php';
 
         if ( $this->DirectAccess )
@@ -316,6 +325,8 @@
         else
         {
             $overrideDirs = $this->overrideDirs();
+            $fileName = $this->FileName;
+            $rootDir = $this->RootDir;
             foreach ( $overrideDirs as $overrideDirItem )
             {
                 $overrideDir = $overrideDirItem[0];
@@ -321,9 +332,10 @@
                 $overrideDir = $overrideDirItem[0];
                 $isGlobal = $overrideDirItem[1];
                 if ( $isGlobal )
-                    $overrideFile = eZDir::path( array( $overrideDir, $this->FileName ) );
-                else
-                    $overrideFile = eZDir::path( array( $this->RootDir, $overrideDir, $this->FileName ) );
+                    $overrideFile = eZDir::path( array( $overrideDir, $fileName ) );
+                 else
+                    $overrideFile = eZDir::path( array( $rootDir, $overrideDir, $fileName ) );
+
                 if ( file_exists( $overrideFile . '.php' ) )
                 {
                     $inputFiles[] = $overrideFile . '.php';
@@ -328,19 +340,21 @@
                 {
                     $inputFiles[] = $overrideFile . '.php';
                 }
+
                 if ( file_exists( $overrideFile ) )
+                {
                     $inputFiles[] = $overrideFile;
+                }
 
-                if ( $isGlobal )
-                    $overrideFile = eZDir::path( array( $overrideDir, $this->FileName . '.append' ) );
-                else
-                    $overrideFile = eZDir::path( array( $this->RootDir, $overrideDir, $this->FileName . '.append' ) );
-                if ( file_exists( $overrideFile . '.php' ) )
+                if ( file_exists( $overrideFile . '.append.php' ) )
                 {
-                    $inputFiles[] = $overrideFile . '.php';
+                    $inputFiles[] = $overrideFile . '.append.php';
                 }
-                if ( file_exists( $overrideFile ) )
-                    $inputFiles[] = $overrideFile;
+
+                if ( file_exists( $overrideFile . '.append' ) )
+                {
+                    $inputFiles[] = $overrideFile . '.append';
+                }
             }
         }
     }
@@ -357,25 +371,36 @@
             $this->reset();
         $cachedDir = "var/cache/ini/";
 
-        eZDebug::accumulatorStart( 'ini_find_files', 'ini_load', 'FindInputFiles' );
-        $this->findInputFiles( $inputFiles, $iniFile );
-        eZDebug::accumulatorStop( 'ini_find_files' );
-        if ( count( $inputFiles ) == 0 )
+        if ( !self::$performanceMode )
         {
-            eZDebug::accumulatorStop( 'ini' );
-            return false;
+            eZDebug::accumulatorStart( 'ini_find_files', 'ini_load', 'FindInputFiles' );
+            $this->findInputFiles( $inputFiles, $iniFile );
+            eZDebug::accumulatorStop( 'ini_find_files' );
+            if ( count( $inputFiles ) === 0 )
+            {
+                eZDebug::accumulatorStop( 'ini' );
+                return false;
+            }
+
+            $md5_input = '';
+            $inputTime = false;
+            foreach ( $inputFiles as $inputFile )
+            {
+                $md5_input .= $inputFile. "\n";
+                $fileTime = filemtime( $inputFile );
+                if ( $inputTime === false or
+                     $fileTime > $inputTime )
+                    $inputTime = $fileTime;
+            }
         }
-
-/*        if ( strstr( end( $inputFiles ), 'settings/override/' ) )
+        else
         {
-            $overrideINIFile = array_pop( $inputFiles );
-        }*/
+            $md5_input = $this->FileName . $this->RootDir;
 
-        $md5_input = '';
-        foreach ( $inputFiles as $inputFile )
-        {
-            $md5_input .= $inputFile. "\n";
+            if ( isset( $GLOBALS['eZCurrentAccess'] ) )
+                $md5_input .= $GLOBALS['eZCurrentAccess']['name'];
         }
+
         if ( $this->UseTextCodec )
         {
             //include_once( "lib/ezi18n/classes/eztextcodec.php" );
@@ -385,7 +410,7 @@
         {
             $md5_input .= '-placement';
         }
-        $fileName = md5( $md5_input ) . ".php";
+        $fileName = md5( $md5_input ) . '.php';
         $cachedFile = $cachedDir . $fileName;
         if ( $placement )
         {
@@ -396,16 +421,6 @@
             $this->CacheFile = $cachedFile;
         }
 
-        $inputTime = false;
-        // check for modifications
-        foreach ( $inputFiles as $inputFile )
-        {
-            $fileTime = filemtime( $inputFile );
-            if ( $inputTime === false or
-                 $fileTime > $inputTime )
-                $inputTime = $fileTime;
-        }
-
         $loadCache = false;
         $cacheTime = false;
         if ( file_exists( $cachedFile ) )
@@ -410,14 +425,17 @@
         $cacheTime = false;
         if ( file_exists( $cachedFile ) )
         {
-            $fileInfo = @stat( $cachedFile );
-            if ( $fileInfo )
+            $loadCache = true;
+            if ( !self::$performanceMode )
             {
-                $cacheTime = $fileInfo['mtime'];
-                $loadCache = true;
-                if ( $cacheTime < $inputTime )
+                $fileInfo = @stat( $cachedFile );
+                if ( $fileInfo )
                 {
-                    $loadCache = false;
+                    $cacheTime = $fileInfo['mtime'];
+                    if ( $cacheTime < $inputTime )
+                    {
+                        $loadCache = false;
+                    }
                 }
             }
         }
@@ -457,6 +475,18 @@
         }
         if ( !$useCache )
         {
+            if ( !isset( $inputFiles ) )
+            {
+                eZDebug::accumulatorStart( 'ini_find_files', 'ini_load', 'FindInputFiles' );
+                $this->findInputFiles( $inputFiles, $iniFile );
+                eZDebug::accumulatorStop( 'ini_find_files' );
+                if ( count( $inputFiles ) === 0 )
+                {
+                    eZDebug::accumulatorStop( 'ini' );
+                    return false;
+                }
+            }
+        
             eZDebug::accumulatorStart( 'ini_files_1', 'ini_load', 'Parse' );
             $this->parse( $inputFiles, $iniFile, false, $placement );
             eZDebug::accumulatorStop( 'ini_files_1' );
@@ -733,9 +763,8 @@
             $pathArray[] = 'override';
             $dirArray[] = 'override';
         }
-        if ( is_string( $useOverride ) and
-             $useOverride == "append" )
-            $fileName .= ".append";
+        if ( $useOverride === 'append' )
+            $fileName .= '.append';
         if ( $suffix !== false )
             $fileName .= $suffix;
 
