Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 629 - Remove duplicate strtoupper #825

Closed
wants to merge 1 commit into from
Closed

Issue 629 - Remove duplicate strtoupper #825

wants to merge 1 commit into from

Conversation

matt-allan
Copy link

@matt-allan matt-allan commented Dec 18, 2018

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

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

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.

I think the line could just be changed to $pCoordinate = strtoupper($pCoordinate) but I'm not familiar enough with the worksheet references and named ranges to be confident that won't break anything.

// Check cell collection
if ($this->cellCollection->has(strtoupper($pCoordinate))) {
if ($this->cellCollection->has($pCoordinateUpper)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bug to me. Shouldn't get use the same key we checked with has? Based on the code in Cells I think this can return null.

@@ -1214,17 +1217,14 @@ public function getCell($pCoordinate, $createIfNotExists = true)
}
}

// Uppercase coordinate
$pCoordinate = strtoupper($pCoordinate);

if (Coordinate::coordinateIsRange($pCoordinate)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these checks actually need to use the uppercase version as they are only checking for symbols, not letters.

Removing the duplicate strtoupper call has a meaningful impact on
performance since this method is called at least once per cell.
@PowerKiKi PowerKiKi closed this in ff6f4f4 Jan 2, 2019
guillaume-ro-fr pushed a commit to guillaume-ro-fr/PhpSpreadsheet that referenced this pull request Jun 12, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant