Skip to content

Commit

Permalink
A couple of micro-optimizations found using a profileA couple of micr…
Browse files Browse the repository at this point in the history
…o-optimizations found using a profilerr
  • Loading branch information
lorenzo committed Dec 6, 2010
1 parent 88a4a66 commit 575a6b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
11 changes: 4 additions & 7 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -300,18 +300,15 @@ class Controller extends Object {
*/
public function __construct($request = null) {
if ($this->name === null) {
$r = null;
if (!preg_match('/(.*)Controller/i', get_class($this), $r)) {
echo __("Controller::__construct() : Can not get or parse my own class name, exiting.");
$this->_stop();
}
$this->name = $r[1];
$this->name = substr(get_class($this), 0, strlen(get_class($this)) -10);
}

if ($this->viewPath == null) {
$this->viewPath = Inflector::underscore($this->name);
}
$this->modelClass = Inflector::classify($this->name);
if (empty($this->uses)) {
$this->modelClass = Inflector::singularize($this->name);
}
$this->modelKey = Inflector::underscore($this->modelClass);
$this->Components = new ComponentCollection();

Expand Down
11 changes: 6 additions & 5 deletions lib/Cake/Model/CakeSession.php
Expand Up @@ -345,11 +345,12 @@ public static function valid() {
* @return boolean
*/
protected static function _validAgentAndTime() {
$config = self::read('Config');
$validAgent = (
Configure::read('Session.checkAgent') === false ||
self::$_userAgent == self::read('Config.userAgent')
self::$_userAgent == $config['userAgent']
);
return ($validAgent && self::$time <= self::read('Config.time'));
return ($validAgent && self::$time <= $config['time']);
}

/**
Expand Down Expand Up @@ -672,14 +673,14 @@ protected static function _startSession() {
* @return void
*/
protected static function _checkValid() {
if (self::read('Config')) {
if ($config = self::read('Config')) {
$sessionConfig = Configure::read('Session');

if (self::_validAgentAndTime()) {
$time = self::read('Config.time');
$time = $config['time'];
self::write('Config.time', self::$sessionTime);
if (isset($sessionConfig['autoRegenerate']) && $sessionConfig['autoRegenerate'] === true) {
$check = self::read('Config.countdown');
$check = $config['countdown'];
$check -= 1;
self::write('Config.countdown', $check);

Expand Down
9 changes: 6 additions & 3 deletions lib/Cake/Utility/Set.php
Expand Up @@ -583,12 +583,14 @@ public static function classicExtract($data, $path = null) {
return $data;
}

if (!is_array($path)) {
if (is_string($path) && strpos($path, '{') !== false) {
$path = String::tokenize($path, '.', '{', '}');
} else {
$path = explode('.', $path);
}
$tmp = array();

if (!is_array($path) || empty($path)) {
if (empty($path)) {
return null;
}

Expand Down Expand Up @@ -662,11 +664,12 @@ public static function insert($list, $path, $data = null) {
}
$_list =& $list;

$count = count($path);
foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
$key = intval($key);
}
if ($i === count($path) - 1) {
if ($i === $count - 1) {
$_list[$key] = $data;
} else {
if (!isset($_list[$key])) {
Expand Down

0 comments on commit 575a6b4

Please sign in to comment.