File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -61,18 +61,18 @@ abstract public function decode(string $strippedCode): CodeArea;
6161
6262 /**
6363 * Returns a static instance of the appropriate code calculator depending on whether the current PHP is 32-bit/64-bit.
64- *
6564 * 32-bit PHP will get a calculator that uses floats, while 64-bit PHP will get a calculator that uses "long" ints.
6665 *
67- * This is required to allow 32-bit PHP environments to correctly calculate Open Location Codes.
68- *
69- * @return CodeCalculatorFloat The appropriate code calculator.
66+ * This is required to allow 32-bit PHP environments to correctly calculate Open Location Codes, while preserving
67+ * the performance advantage of 64-bit PHP by using integer operations.
68+ * @return CodeCalculatorFloat|CodeCalculatorInt The appropriate code calculator.
7069 */
71- public static function getDefaultCalculator (): CodeCalculatorFloat
70+ public static function getDefaultCalculator (): CodeCalculatorFloat | CodeCalculatorInt
7271 {
73- // always give float calculator for now
74- // todo check platform status to give int calculator
75- static $ defaultCalculator = new CodeCalculatorFloat ();
72+ // check PHP environment to give int calculator where possible
73+ // 32-bit PHP has 32-bit int, which uses 4 bytes i.e. PHP_INT_SIZE = 4
74+ // initializing static variables with constructors is only allowed for PHP 8.3+
75+ static $ defaultCalculator = PHP_INT_SIZE > 4 ? new CodeCalculatorInt () : new CodeCalculatorFloat ();
7676 return $ defaultCalculator ;
7777 }
7878}
You can’t perform that action at this time.
0 commit comments