Skip to content

Commit

Permalink
Optimized iterating over StringValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
smuuf committed Mar 12, 2020
1 parent 52302ab commit 7385e50
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/structures/StringValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ public function getIterator(): \Iterator {
*/
private static function utfSplit(string $string): \Generator {

static $set = "UTF-8";
$strlen = \mb_strlen($string);
while ($strlen) {
yield new self(\mb_substr($string, 0, 1, "UTF-8"));
$string = \mb_substr($string, 1, $strlen, "UTF-8");
$strlen = \mb_strlen($string);
for ($i = 0; $i < $strlen; $i++) {
yield new self(\mb_substr($string, $i, 1));
}

}
Expand Down

0 comments on commit 7385e50

Please sign in to comment.