Browse Source

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.
Jose Lorenzo Rodriguez 11 years ago
parent
commit
e03da168f0
1 changed files with 13 additions and 8 deletions
  1. 13 8
      src/ORM/Entity.php

+ 13 - 8
src/ORM/Entity.php

@@ -56,6 +56,19 @@ class Entity implements EntityInterface
         ];
         ];
         $this->_className = get_class($this);
         $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)) {
         if (!empty($properties)) {
             $this->set($properties, [
             $this->set($properties, [
                 'setter' => $options['useSetters'],
                 'setter' => $options['useSetters'],
@@ -66,13 +79,5 @@ class Entity implements EntityInterface
         if ($options['markClean']) {
         if ($options['markClean']) {
             $this->clean();
             $this->clean();
         }
         }
-
-        if ($options['markNew'] !== null) {
-            $this->isNew($options['markNew']);
-        }
-
-        if (!empty($options['source'])) {
-            $this->source($options['source']);
-        }
     }
     }
 }
 }