Minor performance tweaks

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@63786 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2010-11-16 16:44:32 +00:00
parent 012348ac4a
commit bd46652fb1
2 changed files with 17 additions and 17 deletions

View File

@ -2042,7 +2042,7 @@ class PHPExcel_Calculation {
*/ */
public static function _unwrapResult($value) { public static function _unwrapResult($value) {
if (is_string($value)) { if (is_string($value)) {
if ((strlen($value) > 0) && ($value{0} == '"') && (substr($value,-1) == '"')) { if ((isset($value{0})) && ($value{0} == '"') && (substr($value,-1) == '"')) {
return substr($value,1,-1); return substr($value,1,-1);
} }
// Convert numeric errors to NaN error // Convert numeric errors to NaN error
@ -2150,10 +2150,9 @@ class PHPExcel_Calculation {
// Basic validation that this is indeed a formula // Basic validation that this is indeed a formula
// We return an empty array if not // We return an empty array if not
$formula = trim($formula); $formula = trim($formula);
if ((strlen($formula) == 0) || ($formula{0} != '=')) return array(); if ((!isset($formula{0})) || ($formula{0} != '=')) return array();
$formula = trim(substr($formula,1)); $formula = trim(substr($formula,1));
$formulaLength = strlen($formula); if (!isset($formula{0})) return array();
if ($formulaLength < 1) return array();
// Parse the formula and return the token stack // Parse the formula and return the token stack
return $this->_parseFormula($formula); return $this->_parseFormula($formula);
@ -2208,7 +2207,7 @@ class PHPExcel_Calculation {
$formula = trim($formula); $formula = trim($formula);
if ($formula{0} != '=') return self::_wrapResult($formula); if ($formula{0} != '=') return self::_wrapResult($formula);
$formula = trim(substr($formula,1)); $formula = trim(substr($formula,1));
if (strlen($formula) < 1) return self::_wrapResult($formula); if (!isset($formula{0})) return self::_wrapResult($formula);
$wsTitle = "\x00Wrk"; $wsTitle = "\x00Wrk";
if (!is_null($pCell)) { if (!is_null($pCell)) {
@ -3280,9 +3279,9 @@ class PHPExcel_Calculation {
$stack->push('Value',$token); $stack->push('Value',$token);
// if the token is a named range, push the named range name onto the stack // if the token is a named range, push the named range name onto the stack
} elseif (preg_match('/^'.self::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $token, $matches)) { } elseif (preg_match('/^'.self::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $token, $matches)) {
echo 'Token is a named range<br />'; // echo 'Token is a named range<br />';
$namedRange = $matches[6]; $namedRange = $matches[6];
echo 'Named Range is '.$namedRange.'<br />'; // echo 'Named Range is '.$namedRange.'<br />';
$this->_writeDebug('Evaluating Named Range '.$namedRange); $this->_writeDebug('Evaluating Named Range '.$namedRange);
$cellValue = $this->extractNamedRange($namedRange, ((null !== $pCell) ? $pCellParent : null), false); $cellValue = $this->extractNamedRange($namedRange, ((null !== $pCell) ? $pCellParent : null), false);
$pCell->attach($pCellParent); $pCell->attach($pCellParent);

View File

@ -635,17 +635,18 @@ class PHPExcel_Cell
'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26 'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26
); );
$strLen = strlen($pString); // We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
// Convert column to integer // for improved performance
if ($strLen == 1) { if (isset($pString[0])) {
return $_columnLookup[$pString]; if (!isset($pString[1])) {
} elseif ($strLen == 2) { return $_columnLookup[$pString];
return $_columnLookup[$pString[0]] * 26 + $_columnLookup[$pString[1]]; } elseif(!isset($pString[2])) {
} elseif ($strLen == 3) { return $_columnLookup[$pString[0]] * 26 + $_columnLookup[$pString[1]];
return $_columnLookup[$pString[0]] * 676 + $_columnLookup[$pString[1]] * 26 + $_columnLookup[$pString[2]]; } elseif(!isset($pString[3])) {
} else { return $_columnLookup[$pString[0]] * 676 + $_columnLookup[$pString[1]] * 26 + $_columnLookup[$pString[2]];
throw new Exception("Column string index can not be " . ($strLen != 0 ? "longer than 3 characters" : "empty") . "."); }
} }
throw new Exception("Column string index can not be " . ((isset($pString[0])) ? "longer than 3 characters" : "empty") . ".");
} }
/** /**