Skip to content

Commit b37d75f

Browse files
ConnectGridPowerKiKi
authored andcommitted
Check $strictNullComparison outside of loops
Might be considered a micro-optimization, but for large sheets, it could make a difference in performance. Only check the `$strictNullComparison` condition once, not for every single cell loop.
1 parent c74255c commit b37d75f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,25 +3148,32 @@ public function fromArray(array $source, mixed $nullValue = null, $startCell = '
31483148
[$startColumn, $startRow] = Coordinate::coordinateFromString($startCell);
31493149

31503150
// Loop through $source
3151-
foreach ($source as $rowData) {
3152-
$currentColumn = $startColumn;
3153-
foreach ($rowData as $cellValue) {
3154-
if ($strictNullComparison) {
3151+
if ($strictNullComparison) {
3152+
foreach ($source as $rowData) {
3153+
$currentColumn = $startColumn;
3154+
foreach ($rowData as $cellValue) {
31553155
if ($cellValue !== $nullValue) {
31563156
// Set cell value
31573157
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
31583158
}
3159-
} else {
3159+
++$currentColumn;
3160+
}
3161+
++$startRow;
3162+
}
3163+
} else {
3164+
foreach ($source as $rowData) {
3165+
$currentColumn = $startColumn;
3166+
foreach ($rowData as $cellValue) {
31603167
if ($cellValue != $nullValue) {
31613168
// Set cell value
31623169
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
31633170
}
3171+
++$currentColumn;
31643172
}
3165-
++$currentColumn;
3173+
++$startRow;
31663174
}
3167-
++$startRow;
31683175
}
3169-
3176+
31703177
return $this;
31713178
}
31723179

0 commit comments

Comments
 (0)