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

Performance optimization (dupplicate call of strtoupper and multiple calls auf preg_replace) #1040

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/PhpSpreadsheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ public function getStyle($pCellCoordinate = 'A1')
$this->parent->setActiveSheetIndex($this->parent->getIndex($this));

// set cell coordinate as active
$this->setSelectedCells(strtoupper($pCellCoordinate));
$this->setSelectedCells($pCellCoordinate);

return $this->parent->getCellXfSupervisor();
}
Expand Down Expand Up @@ -2420,18 +2420,10 @@ public function setSelectedCells($pCoordinate = 'A1')
{
// Uppercase coordinate
$pCoordinate = strtoupper($pCoordinate);

// Convert 'A' to 'A:A'
$pCoordinate = preg_replace('/^([A-Z]+)$/', '${1}:${1}', $pCoordinate);

// Convert '1' to '1:1'
$pCoordinate = preg_replace('/^([0-9]+)$/', '${1}:${1}', $pCoordinate);

// Convert 'A:C' to 'A1:C1048576'
$pCoordinate = preg_replace('/^([A-Z]+):([A-Z]+)$/', '${1}1:${2}1048576', $pCoordinate);

// Convert '1:3' to 'A1:XFD3'
$pCoordinate = preg_replace('/^([0-9]+):([0-9]+)$/', 'A${1}:XFD${2}', $pCoordinate);
$search = ['/^([A-Z]+)$/', '/^([0-9]+)$/', '/^([A-Z]+):([A-Z]+)$/', '/^([0-9]+):([0-9]+)$/'];
$replace = ['${1}:${1}', '${1}:${1}', '${1}1:${2}1048576', 'A${1}:XFD${2}'];
// Convert 'A' to 'A:A', '1' to '1:1', 'A:C' to 'A1:C1048576', '1:3' to 'A1:XFD3'
$pCoordinate = preg_replace($search, $replace, $pCoordinate);

if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) {
list($first) = Cell::splitRange($pCoordinate);
Expand Down