swiftlang/swift

[SR-3396] `reversed` for sequences and forward collections and should return a `ReversedRandomAccessCollection<[Iterator.Element]>`

Open

#45.984 geöffnet am 12. Dez. 2016

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Swift (10.719 Forks)batch import
affects ABIgood first issueimprovementstandard libraryswift evolution proposal needed

Repository-Metriken

Stars
 (69.989 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 8T 17h) (510 gemergte PRs in 30 T)

Beschreibung

Previous ID SR-3396
Radar rdar://problem/21098134
Original Reporter @airspeedswift
Type Improvement

Attachment: Download

Votes 0
Component/s Standard Library
Labels Improvement, AffectsABI, StarterProposal
Assignee None
Priority Medium

md5: 34c0ebf025eb58406a81d44f15afed48

Issue Description:

Currently calling reversed() on a bi-directional and random-access collections returns a ReversedCollection and ReversedRandomAccessCollection respectively. This is because the view can be placed over the underlying collection at no cost – it's just a question of transforming the index appropriately and then accessing the underlying base collection.

For sequences and forward-only collections, however, this can't be done. So for these, the contents are read into an array and then that array is in-place reversed. But the second step is unnecessary – the array, once created, could just be returned wrapped in a ReversedRandomAccessCollection. As well as efficiency, this would have the benefit of making these methods more consistent across the board in what they return.

Contributor Guide