Skip to content

Commit 25c9fae

Browse files
authored
Merge pull request #9593 from airspeedswift/restore-inline-first
2 parents fb5734c + efd4edf commit 25c9fae

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

stdlib/public/core/Collection.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,12 +1359,15 @@ extension Collection {
13591359
/// // Prints "10"
13601360
@_inlineable
13611361
public var first: Element? {
1362-
// NB: Accessing `startIndex` may not be O(1) for some lazy collections,
1363-
// so instead of testing `isEmpty` and then returning the first element,
1364-
// we'll just rely on the fact that the iterator always yields the
1365-
// first element first.
1366-
var i = makeIterator()
1367-
return i.next()
1362+
@inline(__always)
1363+
get {
1364+
// NB: Accessing `startIndex` may not be O(1) for some lazy collections,
1365+
// so instead of testing `isEmpty` and then returning the first element,
1366+
// we'll just rely on the fact that the iterator always yields the
1367+
// first element first.
1368+
var i = makeIterator()
1369+
return i.next()
1370+
}
13681371
}
13691372

13701373
// TODO: swift-3-indexing-model - uncomment and replace above ready (or should we still use the iterator one?)

0 commit comments

Comments
 (0)