Skip to content

Commit

Permalink
Merge pull request #589 from shama/patch-substr-optimizations
Browse files Browse the repository at this point in the history
substr() optimizations throughout core
  • Loading branch information
lorenzo committed Mar 28, 2012
2 parents 47558e8 + e2a46f7 commit c67feb0
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Console/Command/Task/TestTask.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Console/Command/UpgradeShell.php
Expand Up @@ -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}->/",
Expand Down
3 changes: 0 additions & 3 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Behavior/ContainableBehavior.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -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)));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/basics.php
Expand Up @@ -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'));
Expand Down

0 comments on commit c67feb0

Please sign in to comment.