Browse Source

A couple of micro-optimizations found using a profileA couple of micro-optimizations found using a profilerr

José Lorenzo Rodríguez 15 years ago
parent
commit
575a6b4b78
3 changed files with 16 additions and 15 deletions
  1. 4 7
      lib/Cake/Controller/Controller.php
  2. 6 5
      lib/Cake/Model/CakeSession.php
  3. 6 3
      lib/Cake/Utility/Set.php

+ 4 - 7
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();
 

+ 6 - 5
lib/Cake/Model/CakeSession.php

@@ -345,11 +345,12 @@ class CakeSession {
  * @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 @@ class CakeSession {
  * @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);
 

+ 6 - 3
lib/Cake/Utility/Set.php

@@ -583,12 +583,14 @@ class Set {
 			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 @@ class Set {
 		}
 		$_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])) {