summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-01-10 11:50:07 +0100
committerLukas Reschke <lukas@owncloud.com>2015-01-10 12:06:51 +0100
commit310424db5d57536edcc9238224415756a1c8a624 (patch)
treeadc4acf8c090d1b5c03c6b59254dfa45feeb4afb /lib
parentae3483299cc8bfc226d8fe2a2501fd32c745c745 (diff)
downloadnextcloud-server-310424db5d57536edcc9238224415756a1c8a624.tar.gz
nextcloud-server-310424db5d57536edcc9238224415756a1c8a624.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/view.php6
1 files changed, 4 insertions, 2 deletions
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");
}
}