From 575a6b4b78a117d6b4794beaeed0909370d40896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Lorenzo=20Rodri=CC=81guez?= Date: Mon, 6 Dec 2010 09:38:06 -0430 Subject: [PATCH] A couple of micro-optimizations found using a profileA couple of micro-optimizations found using a profilerr --- lib/Cake/Controller/Controller.php | 11 ++++------- lib/Cake/Model/CakeSession.php | 11 ++++++----- lib/Cake/Utility/Set.php | 9 ++++++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index ed0ac3e6ad6..7d7c58bb5c4 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -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(); diff --git a/lib/Cake/Model/CakeSession.php b/lib/Cake/Model/CakeSession.php index 973a655afe7..fd67272ad24 100644 --- a/lib/Cake/Model/CakeSession.php +++ b/lib/Cake/Model/CakeSession.php @@ -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']); } /** @@ -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); diff --git a/lib/Cake/Utility/Set.php b/lib/Cake/Utility/Set.php index 95b499161c9..37a1836d497 100644 --- a/lib/Cake/Utility/Set.php +++ b/lib/Cake/Utility/Set.php @@ -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; } @@ -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])) {