Closes #5792, Inflector optimization by returning replaced values instead of assining before returning

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7940 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-12-18 01:35:27 +00:00
parent d5b86bc4bf
commit eb653b8cba
2 changed files with 9 additions and 21 deletions

View file

@ -137,7 +137,6 @@ class Inflector extends Object {
$instance[0]->__singularRules = $singularRules;
$instance[0]->__uninflectedSingular = $uninflectedPlural;
$instance[0]->__irregularSingular = array_flip($irregularPlural);
}
}
return $instance[0];
@ -216,7 +215,6 @@ class Inflector extends Object {
'trilby' => 'trilbys',
'turf' => 'turfs');
$pluralRules = Set::pushDiff($this->__pluralRules, $corePluralRules);
$uninflected = Set::pushDiff($this->__uninflectedPlural, $coreUninflectedPlural);
$irregular = Set::pushDiff($this->__irregularPlural, $coreIrregularPlural);
@ -242,8 +240,8 @@ class Inflector extends Object {
if (isset($_this->pluralized[$word])) {
return $_this->pluralized[$word];
}
extract($_this->pluralRules);
if (!isset($regexUninflected) || !isset($regexIrregular)) {
$regexUninflected = __enclose(join( '|', $uninflected));
$regexIrregular = __enclose(join( '|', array_keys($irregular)));
@ -267,8 +265,6 @@ class Inflector extends Object {
return $_this->pluralized[$word];
}
}
$_this->pluralized[$word] = $word;
return $word;
}
/**
* Initializes singular inflection rules.
@ -379,8 +375,8 @@ class Inflector extends Object {
if (isset($_this->singularized[$word])) {
return $_this->singularized[$word];
}
extract($_this->singularRules);
if (!isset($regexUninflected) || !isset($regexIrregular)) {
$regexUninflected = __enclose(join( '|', $uninflected));
$regexIrregular = __enclose(join( '|', array_keys($irregular)));
@ -417,8 +413,7 @@ class Inflector extends Object {
* @link http://book.cakephp.org/view/572/Class-methods
*/
function camelize($lowerCaseAndUnderscoredWord) {
$replace = str_replace(" ", "", ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord)));
return $replace;
return str_replace(" ", "", ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord)));
}
/**
* Returns the given camelCasedWord as an underscored_word.
@ -430,8 +425,7 @@ class Inflector extends Object {
* @link http://book.cakephp.org/view/572/Class-methods
*/
function underscore($camelCasedWord) {
$replace = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
return $replace;
return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
}
/**
* Returns the given underscored_word_group as a Human Readable Word Group.
@ -444,8 +438,7 @@ class Inflector extends Object {
* @link http://book.cakephp.org/view/572/Class-methods
*/
function humanize($lowerCaseAndUnderscoredWord) {
$replace = ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord));
return $replace;
return ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord));
}
/**
* Returns corresponding table name for given model $className. ("people" for the model class "Person").
@ -457,8 +450,7 @@ class Inflector extends Object {
* @link http://book.cakephp.org/view/572/Class-methods
*/
function tableize($className) {
$replace = Inflector::pluralize(Inflector::underscore($className));
return $replace;
return Inflector::pluralize(Inflector::underscore($className));
}
/**
* Returns Cake model class name ("Person" for the database table "people".) for given database table.
@ -470,8 +462,7 @@ class Inflector extends Object {
* @link http://book.cakephp.org/view/572/Class-methods
*/
function classify($tableName) {
$replace = Inflector::camelize(Inflector::singularize($tableName));
return $replace;
return Inflector::camelize(Inflector::singularize($tableName));
}
/**
* Returns camelBacked version of an underscored string.
@ -485,8 +476,7 @@ class Inflector extends Object {
function variable($string) {
$string = Inflector::camelize(Inflector::underscore($string));
$replace = strtolower(substr($string, 0, 1));
$variable = preg_replace('/\\w/', $replace, $string, 1);
return $variable;
return preg_replace('/\\w/', $replace, $string, 1);
}
/**
* Returns a string with all spaces converted to underscores (by default), accented
@ -522,8 +512,7 @@ class Inflector extends Object {
'/\\s+/' => $replacement,
String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '',
);
$string = preg_replace(array_keys($map), array_values($map), $string);
return $string;
return preg_replace(array_keys($map), array_values($map), $string);
}
}
/**

View file

@ -25,7 +25,6 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Core', 'Inflector');
/**
* Short description for class.
*