Skip to content

Commit 47bc56d

Browse files
committed
[String] Fix requiring wcswitch table several times
1 parent d70c35b commit 47bc56d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

AbstractUnicodeString.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ abstract class AbstractUnicodeString extends AbstractString
4949
private const TRANSLIT_TO = ['AE', 'D', 'O', 'TH', 'ss', 'ae', 'd', 'o', 'th', 'D', 'd', 'H', 'h', 'i', 'q', 'L', 'l', 'L', 'l', '\'n', 'N', 'n', 'OE', 'oe', 'T', 't', 'b', 'B', 'B', 'b', 'C', 'c', 'D', 'D', 'D', 'd', 'E', 'F', 'f', 'G', 'hv', 'I', 'I', 'K', 'k', 'l', 'N', 'n', 'OI', 'oi', 'P', 'p', 't', 'T', 't', 'T', 'V', 'Y', 'y', 'Z', 'z', 'DZ', 'Dz', 'dz', 'G', 'g', 'd', 'Z', 'z', 'l', 'n', 't', 'j', 'db', 'qp', 'A', 'C', 'c', 'L', 'T', 's', 'z', 'B', 'U', 'E', 'e', 'J', 'j', 'R', 'r', 'Y', 'y', 'b', 'c', 'd', 'd', 'e', 'j', 'g', 'g', 'G', 'h', 'h', 'i', 'I', 'l', 'l', 'l', 'm', 'n', 'n', 'N', 'OE', 'r', 'r', 'r', 'R', 's', 't', 'u', 'v', 'Y', 'z', 'z', 'B', 'G', 'H', 'j', 'L', 'q', 'dz', 'dz', 'ts', 'ls', 'lz', 'A', 'AE', 'B', 'C', 'D', 'D', 'E', 'J', 'K', 'L', 'M', 'O', 'P', 'T', 'U', 'V', 'W', 'Z', 'ue', 'b', 'd', 'f', 'm', 'n', 'p', 'r', 'r', 's', 't', 'z', 'th', 'I', 'p', 'U', 'b', 'd', 'f', 'g', 'k', 'l', 'm', 'n', 'p', 'r', 's', 'v', 'x', 'z', 'a', 'd', 'e', 'e', 'i', 'u', 'a', 's', 's', 'SS', 'LL', 'll', 'V', 'v', 'Y', 'y', '(C)', '(R)', 'CE', 'Cr', 'Fr.', 'L.', 'Pts', 'TL', 'Rs', 'x', 'Rx', 'm/s', 'rad/s', 'C/kg', 'pH', 'V/m', 'A/m', ' 1/4', ' 1/2', ' 3/4', ' 1/3', ' 2/3', ' 1/5', ' 2/5', ' 3/5', ' 4/5', ' 1/6', ' 5/6', ' 1/8', ' 3/8', ' 5/8', ' 7/8', ' 1/', '0', '\'', '\'', ',', '\'', '"', '"', ',,', '"', '\'', '"', '"', '"', '<<', '>>', '<', '>', '-', '-', '-', '-', '-', '-', '-', '-', '-', '||', '/', '[', ']', '*', ',', '.', '<', '>', '<<', '>>', '[', ']', '[', ']', '[', ']', ',', '.', '[', ']', '<<', '>>', '<', '>', ',', '[', ']', '((', '))', '.', ',', '*', '/', '-', '/', '\\', '|', '||', '<<', '>>', '((', '))'];
5050

5151
private static $transliterators = [];
52+
private static $tableZero;
53+
private static $tableWide;
5254

5355
/**
5456
* @return static
@@ -530,39 +532,37 @@ private function wcswidth(string $string): int
530532
return -1;
531533
}
532534

533-
static $tableZero;
534-
if (null === $tableZero) {
535-
$tableZero = require __DIR__.'/Resources/data/wcswidth_table_zero.php';
535+
if (null === self::$tableZero) {
536+
self::$tableZero = require __DIR__.'/Resources/data/wcswidth_table_zero.php';
536537
}
537538

538-
if ($codePoint >= $tableZero[0][0] && $codePoint <= $tableZero[$ubound = \count($tableZero) - 1][1]) {
539+
if ($codePoint >= self::$tableZero[0][0] && $codePoint <= self::$tableZero[$ubound = \count(self::$tableZero) - 1][1]) {
539540
$lbound = 0;
540541
while ($ubound >= $lbound) {
541542
$mid = floor(($lbound + $ubound) / 2);
542543

543-
if ($codePoint > $tableZero[$mid][1]) {
544+
if ($codePoint > self::$tableZero[$mid][1]) {
544545
$lbound = $mid + 1;
545-
} elseif ($codePoint < $tableZero[$mid][0]) {
546+
} elseif ($codePoint < self::$tableZero[$mid][0]) {
546547
$ubound = $mid - 1;
547548
} else {
548549
continue 2;
549550
}
550551
}
551552
}
552553

553-
static $tableWide;
554-
if (null === $tableWide) {
555-
$tableWide = require __DIR__.'/Resources/data/wcswidth_table_wide.php';
554+
if (null === self::$tableWide) {
555+
self::$tableWide = require __DIR__.'/Resources/data/wcswidth_table_wide.php';
556556
}
557557

558-
if ($codePoint >= $tableWide[0][0] && $codePoint <= $tableWide[$ubound = \count($tableWide) - 1][1]) {
558+
if ($codePoint >= self::$tableWide[0][0] && $codePoint <= self::$tableWide[$ubound = \count(self::$tableWide) - 1][1]) {
559559
$lbound = 0;
560560
while ($ubound >= $lbound) {
561561
$mid = floor(($lbound + $ubound) / 2);
562562

563-
if ($codePoint > $tableWide[$mid][1]) {
563+
if ($codePoint > self::$tableWide[$mid][1]) {
564564
$lbound = $mid + 1;
565-
} elseif ($codePoint < $tableWide[$mid][0]) {
565+
} elseif ($codePoint < self::$tableWide[$mid][0]) {
566566
$ubound = $mid - 1;
567567
} else {
568568
$width += 2;

0 commit comments

Comments
 (0)