Skip to content

Commit 333c811

Browse files
author
Mark Baker
committed
Minor performance tweaks to calculation engine
1 parent a0859fd commit 333c811

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

Classes/PHPExcel/Calculation.php

+9-14
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,13 @@ private function _processTokenStack($tokens, $cellID = NULL, PHPExcel_Cell $pCel
34863486

34873487

34883488
private function _validateBinaryOperand($cellID, &$operand, &$stack) {
3489+
if (is_array($operand)) {
3490+
if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) {
3491+
do {
3492+
$operand = array_pop($operand);
3493+
} while (is_array($operand));
3494+
}
3495+
}
34893496
// Numbers, matrices and booleans can pass straight through, as they're already valid
34903497
if (is_string($operand)) {
34913498
// We only need special validations for the operand if it is a string
@@ -3591,25 +3598,13 @@ private function _executeNumericBinaryOperation($cellID,$operand1,$operand2,$ope
35913598
if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) return FALSE;
35923599
if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) return FALSE;
35933600

3594-
$executeMatrixOperation = FALSE;
35953601
// If either of the operands is a matrix, we need to treat them both as matrices
35963602
// (converting the other operand to a matrix if need be); then perform the required
35973603
// matrix operation
35983604
if ((is_array($operand1)) || (is_array($operand2))) {
3599-
// Ensure that both operands are arrays/matrices
3600-
$executeMatrixOperation = TRUE;
3601-
$mSize = array();
3602-
list($mSize[],$mSize[],$mSize[],$mSize[]) = self::_checkMatrixOperands($operand1,$operand2,2);
3603-
3604-
// But if they're both single cell matrices, then we can treat them as simple values
3605-
if (array_sum($mSize) == 4) {
3606-
$executeMatrixOperation = FALSE;
3607-
$operand1 = $operand1[0][0];
3608-
$operand2 = $operand2[0][0];
3609-
}
3610-
}
3605+
// Ensure that both operands are arrays/matrices of the same size
3606+
self::_checkMatrixOperands($operand1, $operand2, 2);
36113607

3612-
if ($executeMatrixOperation) {
36133608
try {
36143609
// Convert operand 1 from a PHP array to a matrix
36153610
$matrix = new PHPExcel_Shared_JAMA_Matrix($operand1);

0 commit comments

Comments
 (0)