diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-01-25 23:06:53 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-01-26 11:35:42 +0100 |
commit | c1e4f9f30563d5eda1718d716d631d6092cd4e28 (patch) | |
tree | 3bb7b6ef891cd80895d4c2c92252a4ccbc0c0cee /lib | |
parent | fe7e726ab228e6ddde7cf1442de9d0db193334a1 (diff) | |
download | nextcloud-server-c1e4f9f30563d5eda1718d716d631d6092cd4e28.tar.gz nextcloud-server-c1e4f9f30563d5eda1718d716d631d6092cd4e28.zip |
Use type casting instead of *val() method
It should be up to 6x faster
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Comments/Manager.php | 20 | ||||
-rw-r--r-- | lib/private/LargeFileHelper.php | 2 | ||||
-rw-r--r-- | lib/private/Route/CachingRouter.php | 2 | ||||
-rw-r--r-- | lib/private/Template/JSConfigHelper.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/files.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/helper.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/template/functions.php | 2 | ||||
-rw-r--r-- | lib/public/Collaboration/Collaborators/SearchResultType.php | 2 |
8 files changed, 20 insertions, 20 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 4357a2eb437..2b43a27b7ac 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -87,14 +87,14 @@ class Manager implements ICommentsManager { * @return array */ protected function normalizeDatabaseData(array $data) { - $data['id'] = strval($data['id']); - $data['parent_id'] = strval($data['parent_id']); - $data['topmost_parent_id'] = strval($data['topmost_parent_id']); + $data['id'] = (string)$data['id']; + $data['parent_id'] = (string)$data['parent_id']; + $data['topmost_parent_id'] = (string)$data['topmost_parent_id']; $data['creation_timestamp'] = new \DateTime($data['creation_timestamp']); if (!is_null($data['latest_child_timestamp'])) { $data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']); } - $data['children_count'] = intval($data['children_count']); + $data['children_count'] = (int)$data['children_count']; return $data; } @@ -171,7 +171,7 @@ class Manager implements ICommentsManager { $resultStatement = $query->execute(); $data = $resultStatement->fetch(\PDO::FETCH_NUM); $resultStatement->closeCursor(); - $children = intval($data[0]); + $children = (int)$data[0]; $comment = $this->get($id); $comment->setChildrenCount($children); @@ -207,7 +207,7 @@ class Manager implements ICommentsManager { if (empty($id)) { return; } - $this->commentsCache[strval($id)] = $comment; + $this->commentsCache[(string)$id] = $comment; } /** @@ -216,7 +216,7 @@ class Manager implements ICommentsManager { * @param mixed $id the comment's id */ protected function uncache($id) { - $id = strval($id); + $id = (string)$id; if (isset($this->commentsCache[$id])) { unset($this->commentsCache[$id]); } @@ -232,7 +232,7 @@ class Manager implements ICommentsManager { * @since 9.0.0 */ public function get($id) { - if (intval($id) === 0) { + if ((int)$id === 0) { throw new \InvalidArgumentException('IDs must be translatable to a number in this implementation.'); } @@ -402,7 +402,7 @@ class Manager implements ICommentsManager { $resultStatement = $query->execute(); $data = $resultStatement->fetch(\PDO::FETCH_NUM); $resultStatement->closeCursor(); - return intval($data[0]); + return (int)$data[0]; } /** @@ -569,7 +569,7 @@ class Manager implements ICommentsManager { ->execute(); if ($affectedRows > 0) { - $comment->setId(strval($qb->getLastInsertId())); + $comment->setId((string)$qb->getLastInsertId()); $this->sendEvent(CommentsEvent::EVENT_ADD, $comment); } diff --git a/lib/private/LargeFileHelper.php b/lib/private/LargeFileHelper.php index 9f18a6acd6b..ea848f83622 100644 --- a/lib/private/LargeFileHelper.php +++ b/lib/private/LargeFileHelper.php @@ -50,7 +50,7 @@ class LargeFileHelper { * PHP platform. */ public function __construct() { - $pow_2_53 = floatval(self::POW_2_53_MINUS_1) + 1.0; + $pow_2_53 = (float)self::POW_2_53_MINUS_1 + 1.0; if ($this->formatUnsignedInteger($pow_2_53) !== self::POW_2_53) { throw new \RuntimeException( 'This class assumes floats to be double precision or "better".' diff --git a/lib/private/Route/CachingRouter.php b/lib/private/Route/CachingRouter.php index 355f9e80c3f..cb1b98d77e6 100644 --- a/lib/private/Route/CachingRouter.php +++ b/lib/private/Route/CachingRouter.php @@ -52,7 +52,7 @@ class CachingRouter extends Router { */ public function generate($name, $parameters = array(), $absolute = false) { asort($parameters); - $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); + $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . (int)$absolute; $cachedKey = $this->cache->get($key); if ($cachedKey) { return $cachedKey; diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php index 9f93ef784bc..65068973e40 100644 --- a/lib/private/Template/JSConfigHelper.php +++ b/lib/private/Template/JSConfigHelper.php @@ -220,8 +220,8 @@ class JSConfigHelper { 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), 'modRewriteWorking' => ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'), - 'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)), - 'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)), + 'sharing.maxAutocompleteResults' => (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0), + 'sharing.minSearchStringLength' => (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0), 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, ]), "oc_appconfig" => json_encode([ diff --git a/lib/private/legacy/files.php b/lib/private/legacy/files.php index ba635d57627..24324bca095 100644 --- a/lib/private/legacy/files.php +++ b/lib/private/legacy/files.php @@ -148,7 +148,7 @@ class OC_Files { self::lockFiles($view, $dir, $files); $streamer->sendHeaders($name); - $executionTime = intval(OC::$server->getIniWrapper()->getNumeric('max_execution_time')); + $executionTime = (int)OC::$server->getIniWrapper()->getNumeric('max_execution_time'); if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { @set_time_limit(0); } @@ -344,7 +344,7 @@ class OC_Files { */ public static function setUploadLimit($size, $files = []) { //don't allow user to break his config - $size = intval($size); + $size = (int)$size; if ($size < self::UPLOAD_MIN_LIMIT_BYTES) { return false; } diff --git a/lib/private/legacy/helper.php b/lib/private/legacy/helper.php index e88e967a57b..cd69b40b76b 100644 --- a/lib/private/legacy/helper.php +++ b/lib/private/legacy/helper.php @@ -141,7 +141,7 @@ class OC_Helper { public static function computerFileSize($str) { $str = strtolower($str); if (is_numeric($str)) { - return floatval($str); + return (float)$str; } $bytes_array = array( @@ -158,7 +158,7 @@ class OC_Helper { 'p' => 1024 * 1024 * 1024 * 1024 * 1024, ); - $bytes = floatval($str); + $bytes = (float)$str; if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) { $bytes *= $bytes_array[$matches[1]]; diff --git a/lib/private/legacy/template/functions.php b/lib/private/legacy/template/functions.php index 2cd439e9e6e..290ffe120a3 100644 --- a/lib/private/legacy/template/functions.php +++ b/lib/private/legacy/template/functions.php @@ -284,7 +284,7 @@ function human_file_size( $bytes ) { function strip_time($timestamp){ $date = new \DateTime("@{$timestamp}"); $date->setTime(0, 0, 0); - return intval($date->format('U')); + return (int)$date->format('U'); } /** diff --git a/lib/public/Collaboration/Collaborators/SearchResultType.php b/lib/public/Collaboration/Collaborators/SearchResultType.php index e4ad888d6e4..e45b26e8dcc 100644 --- a/lib/public/Collaboration/Collaborators/SearchResultType.php +++ b/lib/public/Collaboration/Collaborators/SearchResultType.php @@ -58,7 +58,7 @@ class SearchResultType { * @since 13.0.0 */ protected function getValidatedType($type) { - $type = trim(strval($type)); + $type = trim((string)$type); if($type === '') { throw new \InvalidArgumentException('Type must not be empty'); |