From 99e5a8e919e1f7b83371a8a586fd6d7875f63583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Fri, 10 Feb 2017 09:18:09 +0100 Subject: [PATCH] Use `isset()` instead of `in_array()` for increased performance and code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #82 Signed-off-by: Roland Häder --- src/PhpSpreadsheet/ReferenceHelper.php | 4 ++-- src/PhpSpreadsheet/Writer/Xls/Worksheet.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 23f5ffef..f4073a5f 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -547,7 +547,7 @@ class ReferenceHelper $autoFilterRange = $autoFilter->getRange(); if (!empty($autoFilterRange)) { if ($pNumCols != 0) { - $autoFilterColumns = array_keys($autoFilter->getColumns()); + $autoFilterColumns = $autoFilter->getColumns(); if (count($autoFilterColumns) > 0) { sscanf($pBefore, '%[A-Z]%d', $column, $row); $columnIndex = Cell::columnIndexFromString($column); @@ -559,7 +559,7 @@ class ReferenceHelper $deleteColumn = $columnIndex + $pNumCols - 1; $deleteCount = abs($pNumCols); for ($i = 1; $i <= $deleteCount; ++$i) { - if (in_array(Cell::stringFromColumnIndex($deleteColumn), $autoFilterColumns)) { + if (isset($autoFilterColumns[Cell::stringFromColumnIndex($deleteColumn)])) { $autoFilter->clearColumn(Cell::stringFromColumnIndex($deleteColumn)); } ++$deleteColumn; diff --git a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php index 333fc540..7b050290 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php @@ -518,8 +518,10 @@ class Worksheet extends BIFFwriter foreach ($conditionalStyles as $conditional) { if ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_EXPRESSION || $conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) { - if (!in_array($conditional->getHashCode(), $arrConditional)) { - $arrConditional[] = $conditional->getHashCode(); + if (!isset($arrConditional[$conditional->getHashCode()])) { + // This hash code has been handled + $arrConditional[$conditional->getHashCode()] = true; + // Write CFRULE record $this->writeCFRule($conditional); }