From 508be392e7acf22a78a1f916074e6b2061a7a964 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Thu, 19 Jan 2012 22:36:22 +0000 Subject: [PATCH] Minor performance tweaks git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@85527 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Autoloader.php | 44 +++++++++++++----------- Classes/PHPExcel/Calculation/Logical.php | 44 +++++++++++------------- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/Classes/PHPExcel/Autoloader.php b/Classes/PHPExcel/Autoloader.php index 1b71afc..3c31255 100644 --- a/Classes/PHPExcel/Autoloader.php +++ b/Classes/PHPExcel/Autoloader.php @@ -21,7 +21,7 @@ * @category PHPExcel * @package PHPExcel * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## */ @@ -29,35 +29,39 @@ PHPExcel_Autoloader::Register(); PHPExcel_Shared_ZipStreamWrapper::register(); // check mbstring.func_overload if (ini_get('mbstring.func_overload') & 2) { - throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).'); + throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).'); } PHPExcel_Shared_String::buildCharacterSets(); class PHPExcel_Autoloader { - public static function Register() { - if (function_exists('__autoload')) { - spl_autoload_register('__autoload'); - } - return spl_autoload_register(array('PHPExcel_Autoloader', 'Load')); - } // function Register() + public static function Register() { + if (function_exists('__autoload')) { + // Register any existing autoloader function with SPL, so we don't get any clashes + spl_autoload_register('__autoload'); + } + // Register ourselves with SPL + return spl_autoload_register(array('PHPExcel_Autoloader', 'Load')); + } // function Register() - public static function Load($pObjectName){ - if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPExcel') === False)) { - return false; - } + public static function Load($pObjectName){ + if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPExcel') !== 0)) { + // Either already loaded, or not a PHPExcel class request + return FALSE; + } - $pObjectFilePath = PHPEXCEL_ROOT. - str_replace('_',DIRECTORY_SEPARATOR,$pObjectName). - '.php'; + $pObjectFilePath = PHPEXCEL_ROOT . + str_replace('_',DIRECTORY_SEPARATOR,$pObjectName) . + '.php'; - if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) { - return false; - } + if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) { + // Can't load + return FALSE; + } - require($pObjectFilePath); - } // function Load() + require($pObjectFilePath); + } // function Load() } \ No newline at end of file diff --git a/Classes/PHPExcel/Calculation/Logical.php b/Classes/PHPExcel/Calculation/Logical.php index 56f6cba..28f9510 100644 --- a/Classes/PHPExcel/Calculation/Logical.php +++ b/Classes/PHPExcel/Calculation/Logical.php @@ -58,7 +58,7 @@ class PHPExcel_Calculation_Logical { * @return boolean True */ public static function TRUE() { - return true; + return TRUE; } // function TRUE() @@ -75,7 +75,7 @@ class PHPExcel_Calculation_Logical { * @return boolean False */ public static function FALSE() { - return false; + return FALSE; } // function FALSE() @@ -102,12 +102,12 @@ class PHPExcel_Calculation_Logical { */ public static function LOGICAL_AND() { // Return value - $returnValue = True; + $returnValue = TRUE; // Loop through the arguments $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); - $argCount = 0; - foreach ($aArgs as $arg) { + $argCount = -1; + foreach ($aArgs as $argCount => $arg) { // Is it a boolean value? if (is_bool($arg)) { $returnValue = $returnValue && $arg; @@ -116,19 +116,18 @@ class PHPExcel_Calculation_Logical { } elseif (is_string($arg)) { $arg = strtoupper($arg); if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) { - $arg = true; + $arg = TRUE; } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) { - $arg = false; + $arg = FALSE; } else { return PHPExcel_Calculation_Functions::VALUE(); } $returnValue = $returnValue && ($arg != 0); } - ++$argCount; } // Return - if ($argCount == 0) { + if ($argCount < 0) { return PHPExcel_Calculation_Functions::VALUE(); } return $returnValue; @@ -158,12 +157,12 @@ class PHPExcel_Calculation_Logical { */ public static function LOGICAL_OR() { // Return value - $returnValue = False; + $returnValue = FALSE; // Loop through the arguments $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); - $argCount = 0; - foreach ($aArgs as $arg) { + $argCount = -1; + foreach ($aArgs as $argCount => $arg) { // Is it a boolean value? if (is_bool($arg)) { $returnValue = $returnValue || $arg; @@ -172,19 +171,18 @@ class PHPExcel_Calculation_Logical { } elseif (is_string($arg)) { $arg = strtoupper($arg); if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) { - $arg = true; + $arg = TRUE; } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) { - $arg = false; + $arg = FALSE; } else { return PHPExcel_Calculation_Functions::VALUE(); } $returnValue = $returnValue || ($arg != 0); } - ++$argCount; } // Return - if ($argCount == 0) { + if ($argCount < 0) { return PHPExcel_Calculation_Functions::VALUE(); } 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 * @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); if (is_string($logical)) { $logical = strtoupper($logical); if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) { - return false; + return FALSE; } elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) { - return true; + return TRUE; } else { return PHPExcel_Calculation_Functions::VALUE(); } @@ -259,12 +257,12 @@ class PHPExcel_Calculation_Logical { * @param mixed $returnIfFalse Optional value to return when condition is false * @return mixed The value of returnIfTrue or returnIfFalse determined by condition */ - public static function STATEMENT_IF($condition = true, $returnIfTrue = 0, $returnIfFalse = False) { - $condition = (is_null($condition)) ? True : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition); + public static function STATEMENT_IF($condition = TRUE, $returnIfTrue = 0, $returnIfFalse = FALSE) { + $condition = (is_null($condition)) ? TRUE : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition); $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()