Skip to content

Commit 67c075e

Browse files
committed
reduce the number of intermediate objects when capturing regex values
1 parent cb489c7 commit 67c075e

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

‎src/RegExp.php‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,15 @@ public function capture(Str $string): Map
6969
throw new InvalidRegex(\preg_last_error_msg(), \preg_last_error());
7070
}
7171

72-
/** @var Map<int|string, Str> */
73-
$map = Map::of();
72+
/** @var list<array{int|string, Str}> */
73+
$map = [];
7474

7575
foreach ($matches as $key => $match) {
7676
/** @psalm-suppress RedundantCast Don't trust the types of preg_match */
77-
$map = ($map)(
78-
$key,
79-
Str::of(
80-
(string) $match,
81-
$string->encoding(),
82-
),
83-
);
77+
$map[] = [$key, Str::of((string) $match, $string->encoding())];
8478
}
8579

86-
return $map;
80+
return Map::of(...$map);
8781
}
8882

8983
#[\NoDiscard]

0 commit comments

Comments
 (0)