Skip to content

Commit 92d9b3a

Browse files
authored
Merge pull request #12390 from moiseev/strides
[stdlib] Implement customization points for StrideTo, StrideThrough, and LazyFilterX
2 parents 9c52678 + ba019f3 commit 92d9b3a

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

stdlib/public/core/Filter.swift.gyb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public struct LazyFilterSequence<Base : Sequence>
8484
_base: base.makeIterator(), _include)
8585
}
8686

87+
@_inlineable
88+
public func _customContainsEquatableElement(
89+
_ element: Element
90+
) -> Bool? {
91+
if !_include(element) {
92+
return false
93+
}
94+
if let baseContains = base._customContainsEquatableElement(element) {
95+
return baseContains
96+
}
97+
return nil
98+
}
99+
87100
/// Creates an instance consisting of the elements `x` of `base` for
88101
/// which `isIncluded(x) == true`.
89102
@_inlineable // FIXME(sil-serialize-all)
@@ -152,6 +165,19 @@ public struct ${Self}<
152165
self._predicate = isIncluded
153166
}
154167

168+
@_inlineable
169+
public func _customContainsEquatableElement(
170+
_ element: Element
171+
) -> Bool? {
172+
if !_predicate(element) {
173+
return false
174+
}
175+
if let baseContains = _base._customContainsEquatableElement(element) {
176+
return baseContains
177+
}
178+
return nil
179+
}
180+
155181
/// The position of the first element in a non-empty collection.
156182
///
157183
/// In an empty collection, `startIndex == endIndex`.

stdlib/public/core/Stride.swift.gyb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,23 @@ public struct StrideTo<Element : Strideable> : Sequence, CustomReflectable {
233233
return StrideToIterator(_start: _start, end: _end, stride: _stride)
234234
}
235235

236+
@_inlineable
237+
public func _preprocessingPass<R>(
238+
_ preprocess: () throws -> R
239+
) rethrows -> R? {
240+
return try preprocess()
241+
}
242+
243+
@_inlineable
244+
public func _customContainsEquatableElement(
245+
_ element: Element
246+
) -> Bool? {
247+
if element < _start || _end <= element {
248+
return false
249+
}
250+
return nil
251+
}
252+
236253
@_inlineable
237254
@_versioned
238255
internal init(_start: Element, end: Element, stride: Element.Stride) {
@@ -333,6 +350,23 @@ public struct StrideThrough<
333350
return StrideThroughIterator(_start: _start, end: _end, stride: _stride)
334351
}
335352

353+
@_inlineable
354+
public func _preprocessingPass<R>(
355+
_ preprocess: () throws -> R
356+
) rethrows -> R? {
357+
return try preprocess()
358+
}
359+
360+
@_inlineable
361+
public func _customContainsEquatableElement(
362+
_ element: Element
363+
) -> Bool? {
364+
if element < _start || _end < element {
365+
return false
366+
}
367+
return nil
368+
}
369+
336370
@_inlineable
337371
@_versioned
338372
internal init(_start: Element, end: Element, stride: Element.Stride) {

0 commit comments

Comments
 (0)