mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-28 04:44:20 +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
|
/// element and iterates over every non-nil element from the original
|
||||||
/// `Collection`.
|
/// `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`.
|
/// original `Collection`.
|
||||||
@inlinable
|
@inlinable
|
||||||
public func compacted<Unwrapped>() -> CompactedCollection<Self, Unwrapped>
|
public func compacted<Unwrapped>() -> CompactedCollection<Self, Unwrapped>
|
||||||
|
|||||||
@@ -226,9 +226,15 @@ extension StrideCollection: Collection {
|
|||||||
offsetBy n: Int,
|
offsetBy n: Int,
|
||||||
limitedBy limit: Index
|
limitedBy limit: Index
|
||||||
) -> Index? {
|
) -> Index? {
|
||||||
let distance = i == endIndex
|
// We typically use the ternary operator but this significantly increases
|
||||||
? -((base.count - 1) % stride + 1) + (n - 1) * -stride
|
// compile times when using Swift 5.3.2
|
||||||
: n * -stride
|
// 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(
|
return base.index(
|
||||||
i.base,
|
i.base,
|
||||||
offsetBy: distance,
|
offsetBy: distance,
|
||||||
|
|||||||
Reference in new issue
Block a user