Skip to content

Commit 4c4100f

Browse files
mdznrKyle Macomber
and
Kyle Macomber
committed
Avoid any intermediate heap allocations when advancing indexes
Co-authored-by: Kyle Macomber <[email protected]>
1 parent 70ad269 commit 4c4100f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/Algorithms/Combinations.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ extension Combinations: Sequence {
124124
if kRange.lowerBound < kRange.upperBound {
125125
let advancedLowerBound = kRange.lowerBound + 1
126126
kRange = advancedLowerBound..<kRange.upperBound
127-
self.indexes = Array(base.indices.prefix(kRange.lowerBound))
127+
indexes.removeAll(keepingCapacity: true)
128+
indexes.append(contentsOf: base.indices.prefix(kRange.lowerBound))
128129
}
129130
}
130131

0 commit comments

Comments
 (0)