Performance tweaks to calculating column string from index

This commit is contained in:
MarkBaker 2022-05-10 12:58:34 +02:00
parent a0ad01e91d
commit 55f03a5d38
1 changed files with 2 additions and 1 deletions

View File

@ -324,6 +324,7 @@ abstract class Coordinate
public static function stringFromColumnIndex($columnIndex) public static function stringFromColumnIndex($columnIndex)
{ {
static $indexCache = []; static $indexCache = [];
static $lookupCache = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (!isset($indexCache[$columnIndex])) { if (!isset($indexCache[$columnIndex])) {
$indexValue = $columnIndex; $indexValue = $columnIndex;
@ -331,7 +332,7 @@ abstract class Coordinate
do { do {
$characterValue = ($indexValue % 26) ?: 26; $characterValue = ($indexValue % 26) ?: 26;
$indexValue = ($indexValue - $characterValue) / 26; $indexValue = ($indexValue - $characterValue) / 26;
$base26 = chr($characterValue + 64) . $base26; $base26 = $lookupCache[$characterValue] . $base26;
} while ($indexValue > 0); } while ($indexValue > 0);
$indexCache[$columnIndex] = $base26; $indexCache[$columnIndex] = $base26;
} }