mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-22 04:10:39 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b275ccd212 | ||
|
|
50be2c8b3f |
No files matched your search
@@ -159,7 +159,7 @@ extension Collection {
|
||||
/// element and iterates over every non-nil element from the original
|
||||
/// `Collection`.
|
||||
///
|
||||
/// Complexity: O(*n*) where *n* is the number of elements in the
|
||||
/// Complexity: O(*n*) where *n* is the number of elements in the
|
||||
/// original `Collection`.
|
||||
@inlinable
|
||||
public func compacted<Unwrapped>() -> CompactedCollection<Self, Unwrapped>
|
||||
|
||||
@@ -226,9 +226,15 @@ extension StrideCollection: Collection {
|
||||
offsetBy n: Int,
|
||||
limitedBy limit: Index
|
||||
) -> Index? {
|
||||
let distance = i == endIndex
|
||||
? -((base.count - 1) % stride + 1) + (n - 1) * -stride
|
||||
: n * -stride
|
||||
// We typically use the ternary operator but this significantly increases
|
||||
// compile times when using Swift 5.3.2
|
||||
// https://github.com/apple/swift-algorithms/issues/146
|
||||
let distance: Int
|
||||
if i == endIndex {
|
||||
distance = -((base.count - 1) % stride + 1) + (n - 1) * -stride
|
||||
} else {
|
||||
distance = n * -stride
|
||||
}
|
||||
return base.index(
|
||||
i.base,
|
||||
offsetBy: distance,
|
||||
|
||||
Reference in new issue
Block a user