Skip to content

Commit

Permalink
Remove duplicate strtoupper
Browse files Browse the repository at this point in the history
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 PHPOffice#825
  • Loading branch information
Matt Allan authored and guillaume-ro-fr committed Jun 12, 2019
1 parent 7bd38c4 commit 34f10ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1191,9 +1191,12 @@ 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))) {
return $this->cellCollection->get($pCoordinate);
if ($this->cellCollection->has($pCoordinateUpper)) {
return $this->cellCollection->get($pCoordinateUpper);
}

// Worksheet reference?
Expand All @@ -1214,17 +1217,14 @@ 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) {
throw new Exception('Cell coordinate must not be absolute.');
}

// Create new cell object, if required
return $createIfNotExists ? $this->createNewCell($pCoordinate) : null;
return $createIfNotExists ? $this->createNewCell($pCoordinateUpper) : null;
}

/**
Expand Down

0 comments on commit 34f10ff

Please sign in to comment.