Browse Source

substr() optimizations

Kyle Robinson Young 14 years ago
parent
commit
e2a46f76c7

+ 3 - 3
lib/Cake/Console/Command/Task/TestTask.php

@@ -398,8 +398,8 @@ class TestTask extends BakeTask {
 	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 @@ class TestTask extends BakeTask {
 			$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";
 		}

+ 2 - 1
lib/Cake/Console/Command/UpgradeShell.php

@@ -234,7 +234,8 @@ class UpgradeShell extends AppShell {
 		$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}->/",

+ 0 - 3
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');

+ 1 - 1
lib/Cake/Model/Behavior/ContainableBehavior.php

@@ -304,7 +304,7 @@ class ContainableBehavior extends ModelBehavior {
 					$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;

+ 1 - 1
lib/Cake/View/Helper/FormHelper.php

@@ -786,7 +786,7 @@ class FormHelper extends AppHelper {
 				$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)));
 		}

+ 1 - 1
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'));