From: Lukas Reschke Date: Sat, 10 Jan 2015 10:50:07 +0000 (+0100) Subject: Use isset() instead of strlen() X-Git-Tag: v8.0.0alpha2~4^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=310424db5d57536edcc9238224415756a1c8a624;p=nextcloud-server.git Use isset() instead of strlen() Isset is a native language construct and thus A LOT faster than using strlen() On my local machine this leads to a 1s performance gain for about 1 million paths. Considering that this function will be called a lot for every file operation this makes a noticable difference. --- diff --git a/lib/private/files/view.php b/lib/private/files/view.php index f1c15e197d9..034c49a9059 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -1278,8 +1278,10 @@ class View { private function assertPathLength($path) { $maxLen = min(PHP_MAXPATHLEN, 4000); - $pathLen = strlen($path); - if ($pathLen > $maxLen) { + // Check for the string length - performed using isset() instead of strlen() + // because isset() is about 5x-40x faster. + if(isset($path[$maxLen])) { + $pathLen = strlen($path); throw new \OCP\Files\InvalidPathException("Path length($pathLen) exceeds max path length($maxLen): $path"); } }