Skip to content

Commit 45be09e

Browse files
author
MarkBaker
committed
Minor tweaks to execution speed, including eliminating a method call on storing a cell
1 parent 0171709 commit 45be09e

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,8 +5236,6 @@ public function extractCellRange(&$range = 'A1', ?Worksheet $worksheet = null, $
52365236
$aReferences = Coordinate::extractAllCellReferencesInRange($range);
52375237
$range = "'" . $worksheetName . "'" . '!' . $range;
52385238
if (!isset($aReferences[1])) {
5239-
$currentCol = '';
5240-
$currentRow = 0;
52415239
// Single cell in range
52425240
sscanf($aReferences[0], '%[A-Z]%d', $currentCol, $currentRow);
52435241
if ($worksheet->cellExists($aReferences[0])) {
@@ -5248,8 +5246,6 @@ public function extractCellRange(&$range = 'A1', ?Worksheet $worksheet = null, $
52485246
} else {
52495247
// Extract cell data for all cells in the range
52505248
foreach ($aReferences as $reference) {
5251-
$currentCol = '';
5252-
$currentRow = 0;
52535249
// Extract range
52545250
sscanf($reference, '%[A-Z]%d', $currentCol, $currentRow);
52555251
if ($worksheet->cellExists($reference)) {

src/PhpSpreadsheet/Collection/Cells.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ public function cloneCellCollection(Worksheet $worksheet)
317317

318318
// Store new values
319319
$stored = $newCollection->cache->setMultiple($newValues);
320-
$this->destructIfNeeded($stored, $newCollection, 'Failed to copy cells in cache');
320+
if ($stored === false) {
321+
$this->destructIfNeeded($newCollection, 'Failed to copy cells in cache');
322+
}
321323

322324
return $newCollection;
323325
}
@@ -362,21 +364,21 @@ private function storeCurrentCell(): void
362364
$this->currentCell->detach();
363365

364366
$stored = $this->cache->set($this->cachePrefix . $this->currentCoordinate, $this->currentCell);
365-
$this->destructIfNeeded($stored, $this, "Failed to store cell {$this->currentCoordinate} in cache");
367+
if ($stored === false) {
368+
$this->destructIfNeeded($this, "Failed to store cell {$this->currentCoordinate} in cache");
369+
}
366370
$this->currentCellIsDirty = false;
367371
}
368372

369373
$this->currentCoordinate = null;
370374
$this->currentCell = null;
371375
}
372376

373-
private function destructIfNeeded(bool $stored, self $cells, string $message): void
377+
private function destructIfNeeded(self $cells, string $message): void
374378
{
375-
if (!$stored) {
376-
$cells->__destruct();
379+
$cells->__destruct();
377380

378-
throw new PhpSpreadsheetException($message);
379-
}
381+
throw new PhpSpreadsheetException($message);
380382
}
381383

382384
/**
@@ -416,7 +418,7 @@ public function get($cellCoordinate)
416418
$this->storeCurrentCell();
417419

418420
// Return null if requested entry doesn't exist in collection
419-
if (!$this->has($cellCoordinate)) {
421+
if ($this->has($cellCoordinate) === false) {
420422
return null;
421423
}
422424

0 commit comments

Comments
 (0)