From 8676bd9d9b1267076da78a4add8c394088059aff Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 12 Jan 2015 19:59:37 +0100 Subject: [PATCH] Add cache in charsArray() This is static but confined to this function block, so this doesn't introduce any side effect. The performance gain is really worth it. --- src/Stringy.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Stringy.php b/src/Stringy.php index 7c63c94..47a3d88 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -443,7 +443,10 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess */ protected function charsArray() { - return array( + static $charsArray; + if (isset($charsArray)) return $charsArray; + + return $charsArray = array( 'a' => array('à', 'á', 'â', 'ä', 'ã', 'ā', 'ą', 'ă', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ',