Skip to content

Commit

Permalink
Some small performance optimizations to hydration: using substr/strpo…
Browse files Browse the repository at this point in the history
…s instead of preg_replace, passing the row by reference to prevent endless copies, removing retrieved values from row, removing variable class call for cached_obj().
  • Loading branch information
Jelmer Schreuder committed Apr 28, 2011
1 parent de9e75d commit 0f24564
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions classes/query.php
Expand Up @@ -661,14 +661,15 @@ public function use_subquery()
* @param string model classname to hydrate
* @param array columns to use
*/
public function hydrate($row, $models, &$result, $model = null, $select = null)
public function hydrate(&$row, $models, &$result, $model = null, $select = null)
{
$model = is_null($model) ? $this->model : $model;
$select = is_null($select) ? $this->select() : $select;
$obj = array();
foreach ($select as $s)
{
$obj[preg_replace('/^t[0-9]+(_[a-z]+)?\\./uiD', '', $s[0])] = $row[$s[1]];
$obj[substr($s[0], strpos($s[0], '.') + 1)] = $row[$s[1]];
unset($row[$s[1]]);
}

foreach ($model::primary_key() as $pk)
Expand All @@ -679,7 +680,7 @@ public function hydrate($row, $models, &$result, $model = null, $select = null)
}
}

$cached_obj = $model::cached_object($obj);
$cached_obj = Model::cached_object($obj, $model);
$pk = $model::implode_pk($obj);
if (is_array($result) and ! array_key_exists($pk, $result))
{
Expand Down

0 comments on commit 0f24564

Please sign in to comment.