Merge pull request #2820 from PHPOffice/Performance-Coordinates-2

Performance tweaks to calculating column string from index
This commit is contained in:
Mark Baker 2022-05-10 13:57:28 +02:00 committed by GitHub
commit 4d5a4824c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -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;
}