File tree Expand file tree Collapse file tree 1 file changed +3
-17
lines changed Expand file tree Collapse file tree 1 file changed +3
-17
lines changed Original file line number Diff line number Diff line change @@ -1210,24 +1210,10 @@ extension Collection {
1210
1210
/// // Prints "10"
1211
1211
@inlinable
1212
1212
public var first : Element ? {
1213
- @inline ( __always)
1214
- get {
1215
- // NB: Accessing `startIndex` may not be O(1) for some lazy collections,
1216
- // so instead of testing `isEmpty` and then returning the first element,
1217
- // we'll just rely on the fact that the iterator always yields the
1218
- // first element first.
1219
- var i = makeIterator ( )
1220
- return i. next ( )
1221
- }
1213
+ let start = startIndex
1214
+ if start != endIndex { return self [ start] }
1215
+ else { return nil }
1222
1216
}
1223
-
1224
- // TODO: swift-3-indexing-model - uncomment and replace above ready (or should we still use the iterator one?)
1225
- /// Returns the first element of `self`, or `nil` if `self` is empty.
1226
- ///
1227
- /// - Complexity: O(1)
1228
- // public var first: Element? {
1229
- // return isEmpty ? nil : self[startIndex]
1230
- // }
1231
1217
1232
1218
/// A value less than or equal to the number of elements in the collection.
1233
1219
///
You can’t perform that action at this time.
0 commit comments