Merge pull request #2820 from PHPOffice/Performance-Coordinates-2
Performance tweaks to calculating column string from index
This commit is contained in:
commit
4d5a4824c4
|
|
@ -324,6 +324,7 @@ abstract class Coordinate
|
|||
public static function stringFromColumnIndex($columnIndex)
|
||||
{
|
||||
static $indexCache = [];
|
||||
static $lookupCache = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
||||
if (!isset($indexCache[$columnIndex])) {
|
||||
$indexValue = $columnIndex;
|
||||
|
|
@ -331,7 +332,7 @@ abstract class Coordinate
|
|||
do {
|
||||
$characterValue = ($indexValue % 26) ?: 26;
|
||||
$indexValue = ($indexValue - $characterValue) / 26;
|
||||
$base26 = chr($characterValue + 64) . $base26;
|
||||
$base26 = $lookupCache[$characterValue] . $base26;
|
||||
} while ($indexValue > 0);
|
||||
$indexCache[$columnIndex] = $base26;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue