Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Cache the parent frame/decorator
Browse files Browse the repository at this point in the history
This will cache the parent when splitting elements to another page and
can result in significant reduction in calls to `Frame::get_decorator()`
and `Frame::get_parent()`.

Closes dompdf#1165
  • Loading branch information
Indrek Altpere authored and bsweeney committed Jun 15, 2016
1 parent 35cad89 commit 40f87eb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/FrameDecorator/AbstractFrameDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ abstract class AbstractFrameDecorator extends Frame
*/
private $_positionned_parent;

/**
* Cache for the get_parent wehile loop results
*
* @var Frame
*/
private $_cached_parent;

/**
* Class constructor
*
Expand Down Expand Up @@ -173,6 +180,8 @@ function reset()

$this->_counters = array();

$this->_cached_parent = null; //clear get_parent() cache

// Reset all children
foreach ($this->get_children() as $child) {
$child->reset();
Expand Down Expand Up @@ -403,20 +412,19 @@ function remove_child(Frame $child, $update_node = true)
*/
function get_parent()
{
if ($this->_cached_parent) {
return $this->_cached_parent;
}
$p = $this->_frame->get_parent();
if ($p && $deco = $p->get_decorator()) {
while ($tmp = $deco->get_decorator()) {
$deco = $tmp;
}

return $deco;
return $this->_cached_parent = $deco;
} else {
if ($p) {
return $p;
}
return $this->_cached_parent = $p;
}

return null;
}

/**
Expand Down

0 comments on commit 40f87eb

Please sign in to comment.