200% speed increase for get/set with with new Null object
This commit is contained in:
parent
20990ed204
commit
067fe93cef
@ -41,6 +41,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
* @var mixed $generator
|
||||
*/
|
||||
protected $generator;
|
||||
/**
|
||||
* @var Doctrine_Null $null used for extremely fast SQL null value testing
|
||||
*/
|
||||
protected static $null;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
@ -53,6 +57,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
$this->generator = new Doctrine_IndexGenerator($name);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* initNullObject
|
||||
*/
|
||||
public static function initNullObject(Doctrine_Null $null) {
|
||||
self::$null = $null;
|
||||
}
|
||||
/**
|
||||
* @return object Doctrine_Table
|
||||
*/
|
||||
|
@ -80,7 +80,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
|
||||
$proxies = array();
|
||||
|
||||
for($i = $e; $i < $e2 && $i < $this->count(); $i++):
|
||||
if(is_object($this->data[$i]))
|
||||
if($this->data[$i] instanceof Doctrine_Record)
|
||||
$id = $this->data[$i]->getID();
|
||||
elseif(is_array($this->data[$i]))
|
||||
$id = $this->data[$i][$identifier];
|
||||
@ -120,6 +120,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get
|
||||
* @param mixed $key the key of the record
|
||||
|
@ -25,13 +25,27 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
/**
|
||||
* @var string $root root directory
|
||||
*/
|
||||
private $root;
|
||||
private $root;
|
||||
/**
|
||||
* @var Doctrine_Null $null Doctrine_Null object, used for extremely fast null value checking
|
||||
*/
|
||||
private $null;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
private function __construct() {
|
||||
$this->root = dirname(__FILE__);
|
||||
$this->null = new Doctrine_Null;
|
||||
|
||||
Doctrine_Record::initNullObject($this->null);
|
||||
Doctrine_Collection::initNullObject($this->null);
|
||||
}
|
||||
/**
|
||||
* @return Doctrine_Null
|
||||
*/
|
||||
final public function getNullObject() {
|
||||
return $this->null;
|
||||
}
|
||||
/**
|
||||
* setDefaultAttributes
|
||||
|
@ -84,9 +84,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
*/
|
||||
private static $index = 1;
|
||||
/**
|
||||
* @var Doctrine_Null $nullObject a Doctrine_Null object used for SQL null value testing
|
||||
* @var Doctrine_Null $nullObject a Doctrine_Null object used for extremely fast
|
||||
* SQL null value testing
|
||||
*/
|
||||
private static $nullObject;
|
||||
private static $null;
|
||||
/**
|
||||
* @var integer $oid object identifier
|
||||
*/
|
||||
@ -164,8 +165,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
/**
|
||||
* initNullObject
|
||||
*/
|
||||
public static function initNullObject() {
|
||||
self::$nullObject = new Doctrine_Null;
|
||||
public static function initNullObject(Doctrine_Null $null) {
|
||||
self::$null = $null;
|
||||
}
|
||||
/**
|
||||
* setUp
|
||||
@ -198,7 +199,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
foreach($this->table->getColumnNames() as $name) {
|
||||
if( ! isset($tmp[$name])) {
|
||||
$this->data[$name] = array();
|
||||
$this->data[$name] = self::$null;
|
||||
|
||||
} else {
|
||||
$cols++;
|
||||
@ -231,7 +232,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$this->id = array();
|
||||
|
||||
foreach($names as $name) {
|
||||
$this->id[$name] = isset($this->data[$name])?$this->data[$name]:null;
|
||||
if($this->data[$name] === self::$null)
|
||||
$this->id[$name] = null;
|
||||
else
|
||||
$this->id[$name] = $this->data[$name];
|
||||
}
|
||||
break;
|
||||
endswitch;
|
||||
@ -408,8 +412,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
public function get($name) {
|
||||
if(isset($this->data[$name])) {
|
||||
|
||||
// check if the property is not loaded (= it is an empty array)
|
||||
if(is_array($this->data[$name])) {
|
||||
// check if the property is null (= it is the Doctrine_Null object located in self::$null)
|
||||
if($this->data[$name] === self::$null) {
|
||||
|
||||
// no use trying to load the data from database if the Doctrine_Record is not a proxy
|
||||
if($this->state == Doctrine_Record::STATE_PROXY) {
|
||||
@ -423,7 +427,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$this->state = Doctrine_Record::STATE_CLEAN;
|
||||
}
|
||||
|
||||
if(is_array($this->data[$name]))
|
||||
if($this->data[$name] === self::$null)
|
||||
return null;
|
||||
}
|
||||
return $this->data[$name];
|
||||
@ -453,7 +457,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$value = $id;
|
||||
|
||||
if(isset($this->data[$name])) {
|
||||
if( ! is_array($this->data[$name])) {
|
||||
if($this->data[$name] === self::$null) {
|
||||
if($this->data[$name] !== $value) {
|
||||
switch($this->state):
|
||||
case Doctrine_Record::STATE_CLEAN:
|
||||
|
@ -24,12 +24,12 @@ $test = new GroupTest("Doctrine Framework Unit Tests");
|
||||
|
||||
//$test->addTestCase(new Sensei_UnitTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_SessionTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_TableTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_ValidatorTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_ManagerTestCase());
|
||||
|
Loading…
x
Reference in New Issue
Block a user