Skip to content

Commit

Permalink
Optimizing the Entity constructor by not looping over properties.
Browse files Browse the repository at this point in the history
In the case of hydrating an entity for the first time, there is no
actual need for calling the genering set() method. This change makes
hydrating entities twice as fast.
  • Loading branch information
lorenzo committed Mar 29, 2015
1 parent 40eeefc commit e03da16
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/ORM/Entity.php
Expand Up @@ -56,6 +56,19 @@ public function __construct(array $properties = [], array $options = [])
];
$this->_className = get_class($this);

if (!empty($options['source'])) {
$this->source($options['source']);
}

if ($options['markNew'] !== null) {
$this->isNew($options['markNew']);
}

if (!empty($properties) && $options['markClean'] && !$options['useSetters']) {
$this->_properties = $properties;
return;
}

if (!empty($properties)) {
$this->set($properties, [
'setter' => $options['useSetters'],
Expand All @@ -66,13 +79,5 @@ public function __construct(array $properties = [], array $options = [])
if ($options['markClean']) {
$this->clean();
}

if ($options['markNew'] !== null) {
$this->isNew($options['markNew']);
}

if (!empty($options['source'])) {
$this->source($options['source']);
}
}
}

0 comments on commit e03da16

Please sign in to comment.