Skip to content
This repository was archived by the owner on Jan 2, 2019. It is now read-only.

Add caching for formula caclulation token stack #863

Open
wants to merge 1 commit into
base: 1.8
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Classes/PHPExcel/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,7 @@ public function __destruct()
public function flushInstance()
{
$this->clearCalculationCache();
$this->clearTokenStackCache();
}


Expand Down Expand Up @@ -2232,6 +2233,7 @@ public function setCalculationCacheEnabled($pValue = true)
{
$this->calculationCacheEnabled = $pValue;
$this->clearCalculationCache();
$this->clearTokenStackCache();
}


Expand Down Expand Up @@ -2261,6 +2263,13 @@ public function clearCalculationCache()
$this->calculationCache = array();
}

/**
* Clear calculation token-stack cache
*/
public function clearTokenStackCache() {
$this->_tokenStackCache = array();
}

/**
* Clear calculation cache for a specified worksheet
*
Expand Down Expand Up @@ -2797,7 +2806,16 @@ public function _calculateFormulaValue($formula, $cellID = null, PHPExcel_Cell $

// Parse the formula onto the token stack and calculate the value
$this->cyclicReferenceStack->push($wsCellReference);
$cellValue = $this->processTokenStack($this->_parseFormula($formula, $pCell), $cellID, $pCell);
if (($this->calculationCacheEnabled) && (isset($this->_tokenStackCache[$wsCellReference]))) {
$this->_debugLog->writeDebugLog('Retrieving tokenStack for cell ', $wsCellReference, ' from cache');
$tokenStack = $this->_tokenStackCache[$wsCellReference];
} else {
$tokenStack = $this->_parseFormula($formula, $pCell);
if ($this->calculationCacheEnabled) {
$this->_tokenStackCache[$wsCellReference] = $tokenStack;
}
}
$cellValue = $this->_processTokenStack($tokenStack, $cellID, $pCell);
$this->cyclicReferenceStack->pop();

// Save to calculation cache
Expand Down