Skip to content
Permalink
Browse files

Optimizing the Entity constructor by not looping over properties.

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 e03da168f0e237634fd07834ee813950382117ac
Showing with 13 additions and 8 deletions.
  1. +13 −8 src/ORM/Entity.php
@@ -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'],
@@ -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.
You can’t perform that action at this time.