Minor performance tweaks
This commit is contained in:
parent
3db129dc52
commit
4f7da29332
|
|
@ -47,15 +47,17 @@ abstract class Coordinate
|
||||||
*
|
*
|
||||||
* @param string $coordinates eg: 'A1', '$B$12'
|
* @param string $coordinates eg: 'A1', '$B$12'
|
||||||
*
|
*
|
||||||
* @return array{0: int, 1: int} Array containing column index and row index (indexes 0 and 1)
|
* @return array{0: int, 1: int, 2: string} Array containing column and row index, and column string
|
||||||
*/
|
*/
|
||||||
public static function indexesFromString(string $coordinates): array
|
public static function indexesFromString(string $coordinates): array
|
||||||
{
|
{
|
||||||
[$col, $row] = self::coordinateFromString($coordinates);
|
[$column, $row] = self::coordinateFromString($coordinates);
|
||||||
|
$column = ltrim($column, '$');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
self::columnIndexFromString(ltrim($col, '$')),
|
self::columnIndexFromString($column),
|
||||||
(int) ltrim($row, '$'),
|
(int) ltrim($row, '$'),
|
||||||
|
$column,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,12 +96,7 @@ class Cells
|
||||||
*/
|
*/
|
||||||
public function has($cellCoordinate)
|
public function has($cellCoordinate)
|
||||||
{
|
{
|
||||||
if ($cellCoordinate === $this->currentCoordinate) {
|
return ($cellCoordinate === $this->currentCoordinate) || isset($this->index[$cellCoordinate]);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the requested entry exists in the index
|
|
||||||
return isset($this->index[$cellCoordinate]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -237,7 +232,7 @@ class Cells
|
||||||
$toRow = $row * self::MAX_COLUMN_ID;
|
$toRow = $row * self::MAX_COLUMN_ID;
|
||||||
$fromRow = --$row * self::MAX_COLUMN_ID;
|
$fromRow = --$row * self::MAX_COLUMN_ID;
|
||||||
foreach ($this->index as $coordinate) {
|
foreach ($this->index as $coordinate) {
|
||||||
if ($coordinate < $fromRow || $coordinate > $toRow) {
|
if ($coordinate < $fromRow || $coordinate >= $toRow) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$column = $coordinate % self::MAX_COLUMN_ID;
|
$column = $coordinate % self::MAX_COLUMN_ID;
|
||||||
|
|
|
||||||
|
|
@ -181,13 +181,6 @@ class Worksheet implements IComparable
|
||||||
*/
|
*/
|
||||||
private $conditionalStylesCollection = [];
|
private $conditionalStylesCollection = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the current cell collection sorted already?
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $cellCollectionIsSorted = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of breaks.
|
* Collection of breaks.
|
||||||
*
|
*
|
||||||
|
|
@ -1336,24 +1329,22 @@ class Worksheet implements IComparable
|
||||||
*/
|
*/
|
||||||
public function createNewCell($coordinate)
|
public function createNewCell($coordinate)
|
||||||
{
|
{
|
||||||
[$column, $row] = Coordinate::coordinateFromString($coordinate);
|
[$column, $row, $columnString] = Coordinate::indexesFromString($coordinate);
|
||||||
$cell = new Cell(null, DataType::TYPE_NULL, $this);
|
$cell = new Cell(null, DataType::TYPE_NULL, $this);
|
||||||
$this->cellCollection->add($coordinate, $cell);
|
$this->cellCollection->add($coordinate, $cell);
|
||||||
$this->cellCollectionIsSorted = false;
|
|
||||||
|
|
||||||
// Coordinates
|
// Coordinates
|
||||||
$aIndexes = Coordinate::indexesFromString($coordinate);
|
if ($column > $this->cachedHighestColumn) {
|
||||||
if ($this->cachedHighestColumn < $aIndexes[0]) {
|
$this->cachedHighestColumn = $column;
|
||||||
$this->cachedHighestColumn = $aIndexes[0];
|
|
||||||
}
|
}
|
||||||
if ($aIndexes[1] > $this->cachedHighestRow) {
|
if ($row > $this->cachedHighestRow) {
|
||||||
$this->cachedHighestRow = $aIndexes[1];
|
$this->cachedHighestRow = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cell needs appropriate xfIndex from dimensions records
|
// Cell needs appropriate xfIndex from dimensions records
|
||||||
// but don't create dimension records if they don't already exist
|
// but don't create dimension records if they don't already exist
|
||||||
$rowDimension = $this->rowDimensions[$row] ?? null;
|
$rowDimension = $this->rowDimensions[$row] ?? null;
|
||||||
$columnDimension = $this->columnDimensions[$column] ?? null;
|
$columnDimension = $this->columnDimensions[$columnString] ?? null;
|
||||||
|
|
||||||
if ($rowDimension !== null && $rowDimension->getXfIndex() > 0) {
|
if ($rowDimension !== null && $rowDimension->getXfIndex() > 0) {
|
||||||
// then there is a row dimension with explicit style, assign it to the cell
|
// then there is a row dimension with explicit style, assign it to the cell
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ return [
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
|
'A',
|
||||||
],
|
],
|
||||||
'A1',
|
'A1',
|
||||||
],
|
],
|
||||||
|
|
@ -12,6 +13,7 @@ return [
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
12,
|
12,
|
||||||
|
'A',
|
||||||
],
|
],
|
||||||
'A12',
|
'A12',
|
||||||
],
|
],
|
||||||
|
|
@ -19,6 +21,7 @@ return [
|
||||||
[
|
[
|
||||||
10,
|
10,
|
||||||
1,
|
1,
|
||||||
|
'J',
|
||||||
],
|
],
|
||||||
'J1',
|
'J1',
|
||||||
],
|
],
|
||||||
|
|
@ -26,6 +29,7 @@ return [
|
||||||
[
|
[
|
||||||
10,
|
10,
|
||||||
20,
|
20,
|
||||||
|
'J',
|
||||||
],
|
],
|
||||||
'J20',
|
'J20',
|
||||||
],
|
],
|
||||||
|
|
@ -33,6 +37,7 @@ return [
|
||||||
[
|
[
|
||||||
35,
|
35,
|
||||||
1,
|
1,
|
||||||
|
'AI',
|
||||||
],
|
],
|
||||||
'AI1',
|
'AI1',
|
||||||
],
|
],
|
||||||
|
|
@ -40,6 +45,7 @@ return [
|
||||||
[
|
[
|
||||||
35,
|
35,
|
||||||
2012,
|
2012,
|
||||||
|
'AI',
|
||||||
],
|
],
|
||||||
'AI2012',
|
'AI2012',
|
||||||
],
|
],
|
||||||
|
|
@ -47,6 +53,7 @@ return [
|
||||||
[
|
[
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
|
'B',
|
||||||
],
|
],
|
||||||
'B3',
|
'B3',
|
||||||
],
|
],
|
||||||
|
|
@ -54,6 +61,7 @@ return [
|
||||||
[
|
[
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
|
'B',
|
||||||
],
|
],
|
||||||
'$B3',
|
'$B3',
|
||||||
],
|
],
|
||||||
|
|
@ -61,6 +69,7 @@ return [
|
||||||
[
|
[
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
|
'B',
|
||||||
],
|
],
|
||||||
'B$3',
|
'B$3',
|
||||||
],
|
],
|
||||||
|
|
@ -68,6 +77,7 @@ return [
|
||||||
[
|
[
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
|
'B',
|
||||||
],
|
],
|
||||||
'$B$3',
|
'$B$3',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue