From e2a46f76c72c0d81ecd14fc0631d19901768d8d2 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Wed, 28 Mar 2012 13:07:26 -0700 Subject: [PATCH] substr() optimizations --- lib/Cake/Console/Command/Task/TestTask.php | 6 +++--- lib/Cake/Console/Command/UpgradeShell.php | 3 ++- lib/Cake/Controller/Controller.php | 3 --- lib/Cake/Model/Behavior/ContainableBehavior.php | 2 +- lib/Cake/View/Helper/FormHelper.php | 2 +- lib/Cake/basics.php | 2 +- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Console/Command/Task/TestTask.php b/lib/Cake/Console/Command/Task/TestTask.php index e90239e0107..6b86f7fbe48 100644 --- a/lib/Cake/Console/Command/Task/TestTask.php +++ b/lib/Cake/Console/Command/Task/TestTask.php @@ -398,8 +398,8 @@ protected function _processController($subject) { protected function _addFixture($name) { $parent = get_parent_class($name); $prefix = 'app.'; - if (strtolower($parent) != 'appmodel' && strtolower(substr($parent, - 8)) == 'appmodel') { - $pluginName = substr($parent, 0, strlen($parent) - 8); + if (strtolower($parent) != 'appmodel' && strtolower(substr($parent, -8)) == 'appmodel') { + $pluginName = substr($parent, 0, -8); $prefix = 'plugin.' . Inflector::underscore($pluginName) . '.'; } $fixture = $prefix . Inflector::underscore($name); @@ -452,7 +452,7 @@ public function generateConstructor($type, $fullClassName) { $construct = "new $fullClassName();\n"; } if ($type == 'controller') { - $className = substr($fullClassName, 0, strlen($fullClassName) - 10); + $className = substr($fullClassName, 0, -10); $construct = "new Test$fullClassName();\n"; $post = "\$this->{$className}->constructClasses();\n"; } diff --git a/lib/Cake/Console/Command/UpgradeShell.php b/lib/Cake/Console/Command/UpgradeShell.php index a7e8e10a040..75acf594eb0 100644 --- a/lib/Cake/Console/Command/UpgradeShell.php +++ b/lib/Cake/Console/Command/UpgradeShell.php @@ -234,7 +234,8 @@ public function helpers() { $helpers = array_merge($pluginHelpers, $helpers); foreach ($helpers as $helper) { $helper = preg_replace('/Helper$/', '', $helper); - $oldHelper = strtolower(substr($helper, 0, 1)) . substr($helper, 1); + $oldHelper = $helper; + $oldHelper{0} = strtolower($oldHelper{0}); $patterns[] = array( "\${$oldHelper} to \$this->{$helper}", "/\\\${$oldHelper}->/", diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index a096296ea26..cebdb9b67dc 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -13,9 +13,6 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -/** - * Include files - */ App::uses('CakeResponse', 'Network'); App::uses('ClassRegistry', 'Utility'); App::uses('ComponentCollection', 'Controller'); diff --git a/lib/Cake/Model/Behavior/ContainableBehavior.php b/lib/Cake/Model/Behavior/ContainableBehavior.php index e5929f29a10..eb9586bb9ad 100644 --- a/lib/Cake/Model/Behavior/ContainableBehavior.php +++ b/lib/Cake/Model/Behavior/ContainableBehavior.php @@ -304,7 +304,7 @@ public function containments(Model $Model, $contain, $containments = array(), $t $option = 'fields'; $val = array($key); if ($key{0} == '(') { - $val = preg_split('/\s*,\s*/', substr(substr($key, 1), 0, -1)); + $val = preg_split('/\s*,\s*/', substr($key, 1, -1)); } elseif (preg_match('/ASC|DESC$/', $key)) { $option = 'order'; $val = $Model->{$name}->alias . '.' . $key; diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 16aaca259b9..6e66f5875e5 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -786,7 +786,7 @@ public function label($fieldName = null, $text = null, $options = array()) { $text = $fieldName; } if (substr($text, -3) == '_id') { - $text = substr($text, 0, strlen($text) - 3); + $text = substr($text, 0, -3); } $text = __(Inflector::humanize(Inflector::underscore($text))); } diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index cad1908e9b7..694e1ab163a 100644 --- a/lib/Cake/basics.php +++ b/lib/Cake/basics.php @@ -308,7 +308,7 @@ function env($key) { if (!strpos($name, '.php')) { $offset = 4; } - return substr($filename, 0, strlen($filename) - (strlen($name) + $offset)); + return substr($filename, 0, -(strlen($name) + $offset)); break; case 'PHP_SELF': return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));