Skip to content

Commit 9c8f9c9

Browse files
Merge pull request #19981 from kamil-tekiela/Fix-performance-of-Collation
Fix performance of collation
2 parents 0422d49 + d9bdfbc commit 9c8f9c9

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

‎src/Charsets/Collation.php‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ final class Collation
2222
*/
2323
private string $description;
2424

25+
/** @var array<string, string|null> */
26+
private static array $suffixesCache = [];
27+
2528
/**
2629
* @param string $name The collation name
2730
* @param string $charset The name of the character set with which the collation is associated
@@ -214,7 +217,11 @@ private function getVariant(string $part): string|null
214217

215218
private function addSuffixes(string $part): string|null
216219
{
217-
return match ($part) {
220+
if (isset(self::$suffixesCache[$part])) {
221+
return self::$suffixesCache[$part];
222+
}
223+
224+
return self::$suffixesCache[$part] = match ($part) {
218225
'ci' => _pgettext('Collation variant', 'case-insensitive'),
219226
'cs' => _pgettext('Collation variant', 'case-sensitive'),
220227
'ai' => _pgettext('Collation variant', 'accent-insensitive'),
@@ -227,10 +234,7 @@ private function addSuffixes(string $part): string|null
227234
};
228235
}
229236

230-
/**
231-
* @return array<int, bool|string|null>
232-
* @psalm-return array{string, bool, bool, string|null}
233-
*/
237+
/** @return array{string, bool, bool, string|null} */
234238
private function getNameForLevel0(
235239
bool $unicode,
236240
bool $unknown,
@@ -347,10 +351,7 @@ private function getNameForLevel0(
347351
return [$name, $unicode, $unknown, $variant];
348352
}
349353

350-
/**
351-
* @return array<int, bool|int|string>
352-
* @psalm-return array{string, int, bool}
353-
*/
354+
/** @return array{string, int, bool} */
354355
private function getNameForLevel1(
355356
bool $unicode,
356357
bool $unknown,

0 commit comments

Comments
 (0)