From bf3e0c93434e04b3d8c3503795091a011873a6f1 Mon Sep 17 00:00:00 2001 From: Matt Allan Date: Tue, 18 Dec 2018 13:17:41 -0500 Subject: [PATCH] Remove duplicate strtoupper Removing the duplicate strtoupper call has a meaningful impact on performance since this method is called at least once per cell. --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Worksheet/Worksheet.php | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c888ae8f2..b5be37d257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix column names if read filter calls in XLSX reader skip columns - [#777](https://github.com/PHPOffice/PhpSpreadsheet/pull/777) - Fix LOOKUP function which was breaking on edge cases - [#796](https://github.com/PHPOffice/PhpSpreadsheet/issues/796) - Fix VLOOKUP with exact matches +- Improved performance when loading large spreadsheets - [#825](https://github.com/PHPOffice/PhpSpreadsheet/pull/825) ## [1.5.2] - 2018-11-25 diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index e9d93af251..9122040045 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -1191,8 +1191,11 @@ public function setCellValueExplicitByColumnAndRow($columnIndex, $row, $value, $ */ public function getCell($pCoordinate, $createIfNotExists = true) { + // Uppercase coordinate + $pCoordinateUpper = strtoupper($pCoordinate); + // Check cell collection - if ($this->cellCollection->has(strtoupper($pCoordinate))) { + if ($this->cellCollection->has($pCoordinateUpper)) { return $this->cellCollection->get($pCoordinate); } @@ -1214,9 +1217,6 @@ public function getCell($pCoordinate, $createIfNotExists = true) } } - // Uppercase coordinate - $pCoordinate = strtoupper($pCoordinate); - if (Coordinate::coordinateIsRange($pCoordinate)) { throw new Exception('Cell coordinate can not be a range of cells.'); } elseif (strpos($pCoordinate, '$') !== false) { @@ -1224,7 +1224,7 @@ public function getCell($pCoordinate, $createIfNotExists = true) } // Create new cell object, if required - return $createIfNotExists ? $this->createNewCell($pCoordinate) : null; + return $createIfNotExists ? $this->createNewCell($pCoordinateUpper) : null; } /**