From 42b1e0ad764e7c00e174835a3b4afbf0bb485c0e Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 26 Oct 2010 12:29:44 +0000 Subject: [PATCH] Minor performance tweaks git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@62808 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Shared/String.php | 18 ++++++------------ Classes/PHPExcel/Worksheet.php | 16 ++++++---------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/Classes/PHPExcel/Shared/String.php b/Classes/PHPExcel/Shared/String.php index 90e1dd27..784c313e 100644 --- a/Classes/PHPExcel/Shared/String.php +++ b/Classes/PHPExcel/Shared/String.php @@ -533,18 +533,15 @@ class PHPExcel_Shared_String public static function CountCharacters($value, $enc = 'UTF-8') { if (self::getIsIconvEnabled()) { - $count = iconv_strlen($value, $enc); - return $count; + return iconv_strlen($value, $enc); } if (self::getIsMbstringEnabled()) { - $count = mb_strlen($value, $enc); - return $count; + return mb_strlen($value, $enc); } // else strlen - $count = strlen($value); - return $count; + return strlen($value); } /** @@ -558,18 +555,15 @@ class PHPExcel_Shared_String public static function Substring($pValue = '', $pStart = 0, $pLength = 0) { if (self::getIsIconvEnabled()) { - $string = iconv_substr($pValue, $pStart, $pLength, 'UTF-8'); - return $string; + return iconv_substr($pValue, $pStart, $pLength, 'UTF-8'); } if (self::getIsMbstringEnabled()) { - $string = mb_substr($pValue, $pStart, $pLength, 'UTF-8'); - return $string; + return mb_substr($pValue, $pStart, $pLength, 'UTF-8'); } // else substr - $string = substr($pValue, $pStart, $pLength); - return $string; + return substr($pValue, $pStart, $pLength); } diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 5f551620..44a95774 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -2089,22 +2089,18 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable if (is_array($source)) { // start coordinate list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($pCell); - $startColumn = PHPExcel_Cell::columnIndexFromString($startColumn) - 1; // Loop through $source - $currentRow = $startRow - 1; - $rowData = null; foreach ($source as $rowData) { - ++$currentRow; - - $rowCount = count($rowData); - for ($i = 0; $i < $rowCount; ++$i) { - if ($rowData[$i] != $nullValue) { + $currentColumn = $startColumn; + foreach($rowData as $cellValue) { + if ($cellValue != $nullValue) { // Set cell value - $this->getCell(PHPExcel_Cell::stringFromColumnIndex($i + $startColumn) . $currentRow) - ->setValue($rowData[$i]); + $this->getCell($currentColumn . $startRow)->setValue($cellValue); } + ++$currentColumn; } + ++$startRow; } } else { throw new Exception("Parameter \$source should be an array.");