diff --git a/Classes/PHPExcel/Calculation.php b/Classes/PHPExcel/Calculation.php index 20b1ec3f5..209c2ec2b 100644 --- a/Classes/PHPExcel/Calculation.php +++ b/Classes/PHPExcel/Calculation.php @@ -2132,6 +2132,7 @@ public function __destruct() public function flushInstance() { $this->clearCalculationCache(); + $this->clearTokenStackCache(); } @@ -2232,6 +2233,7 @@ public function setCalculationCacheEnabled($pValue = true) { $this->calculationCacheEnabled = $pValue; $this->clearCalculationCache(); + $this->clearTokenStackCache(); } @@ -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 * @@ -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