Skip to content

Commit fb917b9

Browse files
[Cache][String] Don't use is_iterable() in perf-critical code paths
1 parent 4b0c896 commit fb917b9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

AbstractString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ abstract public function trimEnd(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF
558558
*/
559559
public function trimPrefix($prefix): static
560560
{
561-
if (is_iterable($prefix)) {
561+
if (\is_array($prefix) || $prefix instanceof \Traversable) { // don't use is_iterable(), it's slow
562562
foreach ($prefix as $s) {
563563
$t = $this->trimPrefix($s);
564564

@@ -592,7 +592,7 @@ abstract public function trimStart(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FE
592592
*/
593593
public function trimSuffix($suffix): static
594594
{
595-
if (is_iterable($suffix)) {
595+
if (\is_array($suffix) || $suffix instanceof \Traversable) { // don't use is_iterable(), it's slow
596596
foreach ($suffix as $s) {
597597
$t = $this->trimSuffix($s);
598598

0 commit comments

Comments
 (0)