Merge pull request #2767 from PHPOffice/CellCollection-Last-Loop-Adjust

Performance tweaks to cell collection
This commit is contained in:
Mark Baker 2022-04-22 16:01:25 +02:00 committed by GitHub
commit 0d014822a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 34 deletions

View File

@ -1175,11 +1175,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Cell/Coordinate.php path: src/PhpSpreadsheet/Cell/Coordinate.php
-
message: "#^Cannot use array destructuring on array\\|null\\.$#"
count: 1
path: src/PhpSpreadsheet/Cell/Coordinate.php
- -
message: "#^Parameter \\#4 \\$currentRow of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:validateRange\\(\\) expects int, string given\\.$#" message: "#^Parameter \\#4 \\$currentRow of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:validateRange\\(\\) expects int, string given\\.$#"
count: 1 count: 1
@ -3120,11 +3115,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Reader/Xml/Style.php path: src/PhpSpreadsheet/Reader/Xml/Style.php
-
message: "#^Cannot use array destructuring on array\\|null\\.$#"
count: 4
path: src/PhpSpreadsheet/ReferenceHelper.php
- -
message: "#^Elseif condition is always true\\.$#" message: "#^Elseif condition is always true\\.$#"
count: 1 count: 1

View File

@ -383,7 +383,7 @@ abstract class Coordinate
// Sort the result by column and row // Sort the result by column and row
$sortKeys = []; $sortKeys = [];
foreach ($cellList as $coord) { foreach ($cellList as $coord) {
[$column, $row] = sscanf($coord, '%[A-Z]%d'); sscanf($coord, '%[A-Z]%d', $column, $row);
$sortKeys[sprintf('%3s%09d', $column, $row)] = $coord; $sortKeys[sprintf('%3s%09d', $column, $row)] = $coord;
} }
ksort($sortKeys); ksort($sortKeys);

View File

@ -4,7 +4,6 @@ namespace PhpOffice\PhpSpreadsheet\Collection;
use Generator; use Generator;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
@ -152,8 +151,6 @@ class Cells
{ {
$sortKeys = []; $sortKeys = [];
foreach ($this->getCoordinates() as $coord) { foreach ($this->getCoordinates() as $coord) {
$column = '';
$row = 0;
sscanf($coord, '%[A-Z]%d', $column, $row); sscanf($coord, '%[A-Z]%d', $column, $row);
$sortKeys[sprintf('%09d%3s', $row, $column)] = $coord; $sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
} }
@ -172,8 +169,6 @@ class Cells
// Lookup highest column and highest row // Lookup highest column and highest row
$col = ['A' => '1A']; $col = ['A' => '1A'];
$row = [1]; $row = [1];
$c = '';
$r = 0;
foreach ($this->getCoordinates() as $coord) { foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
$row[$r] = $r; $row[$r] = $r;
@ -207,9 +202,6 @@ class Cells
*/ */
public function getCurrentColumn() public function getCurrentColumn()
{ {
$column = '';
$row = 0;
sscanf($this->currentCoordinate ?? '', '%[A-Z]%d', $column, $row); sscanf($this->currentCoordinate ?? '', '%[A-Z]%d', $column, $row);
return $column; return $column;
@ -222,9 +214,6 @@ class Cells
*/ */
public function getCurrentRow() public function getCurrentRow()
{ {
$column = '';
$row = 0;
sscanf($this->currentCoordinate ?? '', '%[A-Z]%d', $column, $row); sscanf($this->currentCoordinate ?? '', '%[A-Z]%d', $column, $row);
return (int) $row; return (int) $row;
@ -245,8 +234,6 @@ class Cells
} }
$maxColumn = '1A'; $maxColumn = '1A';
$c = '';
$r = 0;
foreach ($this->getCoordinates() as $coord) { foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
if ($r != $row) { if ($r != $row) {
@ -273,8 +260,6 @@ class Cells
} }
$maxRow = 1; $maxRow = 1;
$c = '';
$r = 0;
foreach ($this->getCoordinates() as $coord) { foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
if ($c != $column) { if ($c != $column) {
@ -341,8 +326,6 @@ class Cells
*/ */
public function removeRow($row): void public function removeRow($row): void
{ {
$c = '';
$r = 0;
foreach ($this->getCoordinates() as $coord) { foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
if ($r == $row) { if ($r == $row) {
@ -358,8 +341,6 @@ class Cells
*/ */
public function removeColumn($column): void public function removeColumn($column): void
{ {
$c = '';
$r = 0;
foreach ($this->getCoordinates() as $coord) { foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
if ($c == $column) { if ($c == $column) {

View File

@ -90,8 +90,8 @@ class ReferenceHelper
*/ */
public static function cellSort($a, $b) public static function cellSort($a, $b)
{ {
[$ac, $ar] = sscanf($a, '%[A-Z]%d'); sscanf($a, '%[A-Z]%d', $ac, $ar);
[$bc, $br] = sscanf($b, '%[A-Z]%d'); sscanf($b, '%[A-Z]%d', $bc, $br);
if ($ar === $br) { if ($ar === $br) {
return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
@ -111,8 +111,8 @@ class ReferenceHelper
*/ */
public static function cellReverseSort($a, $b) public static function cellReverseSort($a, $b)
{ {
[$ac, $ar] = sscanf($a, '%[A-Z]%d'); sscanf($a, '%[A-Z]%d', $ac, $ar);
[$bc, $br] = sscanf($b, '%[A-Z]%d'); sscanf($b, '%[A-Z]%d', $bc, $br);
if ($ar === $br) { if ($ar === $br) {
return -strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); return -strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);