Skip to content

Commit 2a31433

Browse files
committed
Avoid double execution by avoiding Array init
1 parent 5667705 commit 2a31433

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/_StringProcessing/Algorithms/Matching/Matches.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ extension BidirectionalCollection where SubSequence == Substring {
349349
public func matches<Output>(
350350
of r: some RegexComponent<Output>
351351
) -> [Regex<Output>.Match] {
352-
Array(_matches(of: r))
352+
// FIXME: Array init calls count, which double-executes the regex :-(
353+
// FIXME: just return some Collection<Regex<Output>.Match>
354+
var result = Array<Regex<Output>.Match>()
355+
for match in _matches(of: r) {
356+
result.append(match)
357+
}
358+
return result
353359
}
354360
}

0 commit comments

Comments
 (0)