Minor performance tweaks

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@85527 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2012-01-19 22:36:22 +00:00
parent 34f3e8b706
commit 508be392e7
2 changed files with 45 additions and 43 deletions

View File

@ -38,15 +38,18 @@ class PHPExcel_Autoloader
{ {
public static function Register() { public static function Register() {
if (function_exists('__autoload')) { if (function_exists('__autoload')) {
// Register any existing autoloader function with SPL, so we don't get any clashes
spl_autoload_register('__autoload'); spl_autoload_register('__autoload');
} }
// Register ourselves with SPL
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load')); return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
} // function Register() } // function Register()
public static function Load($pObjectName){ public static function Load($pObjectName){
if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPExcel') === False)) { if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPExcel') !== 0)) {
return false; // Either already loaded, or not a PHPExcel class request
return FALSE;
} }
$pObjectFilePath = PHPEXCEL_ROOT . $pObjectFilePath = PHPEXCEL_ROOT .
@ -54,7 +57,8 @@ class PHPExcel_Autoloader
'.php'; '.php';
if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) { if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) {
return false; // Can't load
return FALSE;
} }
require($pObjectFilePath); require($pObjectFilePath);

View File

@ -58,7 +58,7 @@ class PHPExcel_Calculation_Logical {
* @return boolean True * @return boolean True
*/ */
public static function TRUE() { public static function TRUE() {
return true; return TRUE;
} // function TRUE() } // function TRUE()
@ -75,7 +75,7 @@ class PHPExcel_Calculation_Logical {
* @return boolean False * @return boolean False
*/ */
public static function FALSE() { public static function FALSE() {
return false; return FALSE;
} // function FALSE() } // function FALSE()
@ -102,12 +102,12 @@ class PHPExcel_Calculation_Logical {
*/ */
public static function LOGICAL_AND() { public static function LOGICAL_AND() {
// Return value // Return value
$returnValue = True; $returnValue = TRUE;
// Loop through the arguments // Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
$argCount = 0; $argCount = -1;
foreach ($aArgs as $arg) { foreach ($aArgs as $argCount => $arg) {
// Is it a boolean value? // Is it a boolean value?
if (is_bool($arg)) { if (is_bool($arg)) {
$returnValue = $returnValue && $arg; $returnValue = $returnValue && $arg;
@ -116,19 +116,18 @@ class PHPExcel_Calculation_Logical {
} elseif (is_string($arg)) { } elseif (is_string($arg)) {
$arg = strtoupper($arg); $arg = strtoupper($arg);
if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) { if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) {
$arg = true; $arg = TRUE;
} elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) { } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
$arg = false; $arg = FALSE;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
$returnValue = $returnValue && ($arg != 0); $returnValue = $returnValue && ($arg != 0);
} }
++$argCount;
} }
// Return // Return
if ($argCount == 0) { if ($argCount < 0) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
return $returnValue; return $returnValue;
@ -158,12 +157,12 @@ class PHPExcel_Calculation_Logical {
*/ */
public static function LOGICAL_OR() { public static function LOGICAL_OR() {
// Return value // Return value
$returnValue = False; $returnValue = FALSE;
// Loop through the arguments // Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
$argCount = 0; $argCount = -1;
foreach ($aArgs as $arg) { foreach ($aArgs as $argCount => $arg) {
// Is it a boolean value? // Is it a boolean value?
if (is_bool($arg)) { if (is_bool($arg)) {
$returnValue = $returnValue || $arg; $returnValue = $returnValue || $arg;
@ -172,19 +171,18 @@ class PHPExcel_Calculation_Logical {
} elseif (is_string($arg)) { } elseif (is_string($arg)) {
$arg = strtoupper($arg); $arg = strtoupper($arg);
if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) { if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) {
$arg = true; $arg = TRUE;
} elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) { } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
$arg = false; $arg = FALSE;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
$returnValue = $returnValue || ($arg != 0); $returnValue = $returnValue || ($arg != 0);
} }
++$argCount;
} }
// Return // Return
if ($argCount == 0) { if ($argCount < 0) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
return $returnValue; return $returnValue;
@ -211,14 +209,14 @@ class PHPExcel_Calculation_Logical {
* @param mixed $logical A value or expression that can be evaluated to TRUE or FALSE * @param mixed $logical A value or expression that can be evaluated to TRUE or FALSE
* @return boolean The boolean inverse of the argument. * @return boolean The boolean inverse of the argument.
*/ */
public static function NOT($logical) { public static function NOT($logical=FALSE) {
$logical = PHPExcel_Calculation_Functions::flattenSingleValue($logical); $logical = PHPExcel_Calculation_Functions::flattenSingleValue($logical);
if (is_string($logical)) { if (is_string($logical)) {
$logical = strtoupper($logical); $logical = strtoupper($logical);
if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) { if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) {
return false; return FALSE;
} elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) { } elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) {
return true; return TRUE;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
@ -259,12 +257,12 @@ class PHPExcel_Calculation_Logical {
* @param mixed $returnIfFalse Optional value to return when condition is false * @param mixed $returnIfFalse Optional value to return when condition is false
* @return mixed The value of returnIfTrue or returnIfFalse determined by condition * @return mixed The value of returnIfTrue or returnIfFalse determined by condition
*/ */
public static function STATEMENT_IF($condition = true, $returnIfTrue = 0, $returnIfFalse = False) { public static function STATEMENT_IF($condition = TRUE, $returnIfTrue = 0, $returnIfFalse = FALSE) {
$condition = (is_null($condition)) ? True : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition); $condition = (is_null($condition)) ? TRUE : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition);
$returnIfTrue = (is_null($returnIfTrue)) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfTrue); $returnIfTrue = (is_null($returnIfTrue)) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfTrue);
$returnIfFalse = (is_null($returnIfFalse)) ? False : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfFalse); $returnIfFalse = (is_null($returnIfFalse)) ? FALSE : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfFalse);
return ($condition ? $returnIfTrue : $returnIfFalse); return ($condition) ? $returnIfTrue : $returnIfFalse;
} // function STATEMENT_IF() } // function STATEMENT_IF()