Remove duplicate strtoupper

Removing the duplicate strtoupper call has a meaningful impact on
performance since this method is called at least once per cell.

`Worksheet::getCells` currently calls `strtoupper` twice. `strtoupper`
is kind of expensive and this method is called at least once for every
cell in the spreadsheet.  By removing the unnecessary second call the
runtime decreases by 18% when importing a ~100K cell spreadsheet.

Closes #825
This commit is contained in:
Matt Allan 2018-12-18 13:17:41 -05:00 committed by Adrien Crivelli
parent e8c25c33cd
commit ff6f4f4ec0
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
2 changed files with 7 additions and 6 deletions

View File

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Support COUNTIFS multiple arguments - [#830](https://github.com/PHPOffice/PhpSpreadsheet/pull/830)
- Change `libxml_disable_entity_loader()` as shortly as possible - [#819](https://github.com/PHPOffice/PhpSpreadsheet/pull/819)
- Improved memory usage and performance when loading large spreadsheets - [#822](https://github.com/PHPOffice/PhpSpreadsheet/pull/822)
- Improved performance when loading large spreadsheets - [#825](https://github.com/PHPOffice/PhpSpreadsheet/pull/825)
## [1.5.2] - 2018-11-25

View File

@ -1191,9 +1191,12 @@ class Worksheet implements IComparable
*/
public function getCell($pCoordinate, $createIfNotExists = true)
{
// Uppercase coordinate
$pCoordinateUpper = strtoupper($pCoordinate);
// Check cell collection
if ($this->cellCollection->has(strtoupper($pCoordinate))) {
return $this->cellCollection->get($pCoordinate);
if ($this->cellCollection->has($pCoordinateUpper)) {
return $this->cellCollection->get($pCoordinateUpper);
}
// Worksheet reference?
@ -1214,9 +1217,6 @@ class Worksheet implements IComparable
}
}
// 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 @@ class Worksheet implements IComparable
}
// Create new cell object, if required
return $createIfNotExists ? $this->createNewCell($pCoordinate) : null;
return $createIfNotExists ? $this->createNewCell($pCoordinateUpper) : null;
}
/**