Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
airspeedswift opened this issue Dec 12, 2016 · 3 comments
Labels
affects ABI Flag: Affects ABI good first issue Good for newcomers improvement standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@airspeedswift
Copy link
Member

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

Attachment: Download

Additional Detail from JIRA
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.

@swift-ci
Copy link
Contributor

Comment by Alexis Beingessner (JIRA)

Note that this change will probably make debug code slower based on SR-3334.

@airspeedswift
Copy link
Member Author

Looks like SR-3334 was resolved, so same solution hopefully applicable to this.

@swift-ci
Copy link
Contributor

Comment by Daniel Tull (JIRA)

I have some in-progress changes for this. It's a source breaking change, so what would the way forward be with this?

master...danielctull-forks:SR-3396

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added good first issue Good for newcomers swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal and removed StarterProposal labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects ABI Flag: Affects ABI good first issue Good for newcomers improvement standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

No branches or pull requests

3 participants