Merge pull request #13235 from owncloud/cache-normalize-path

Cache results of `normalizePath`
This commit is contained in:
Morris Jobke 2015-01-10 16:32:09 +01:00
commit 74d1a9ea3d
1 changed files with 12 additions and 1 deletions

View File

@ -47,6 +47,8 @@ class Filesystem {
static private $usersSetup = array(); static private $usersSetup = array();
static private $normalizedPathCache = array();
/** /**
* classname which used for hooks handling * classname which used for hooks handling
* used as signalclass in OC_Hooks::emit() * used as signalclass in OC_Hooks::emit()
@ -713,6 +715,12 @@ class Filesystem {
* @return string * @return string
*/ */
public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) { public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) {
$cacheKey = $path.'-'.-$stripTrailingSlash.'-'.$isAbsolutePath;
if(isset(self::$normalizedPathCache[$cacheKey])) {
return self::$normalizedPathCache[$cacheKey];
}
if ($path == '') { if ($path == '') {
return '/'; return '/';
} }
@ -756,7 +764,10 @@ class Filesystem {
//normalize unicode if possible //normalize unicode if possible
$path = \OC_Util::normalizeUnicode($path); $path = \OC_Util::normalizeUnicode($path);
return $windows_drive_letter . $path; $normalizedPath = $windows_drive_letter . $path;
self::$normalizedPathCache[$cacheKey] = $normalizedPath;
return $normalizedPath;
} }
/** /**