swiftlang/swift

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

Open

#45,984 创建于 2016年12月12日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)Swift (10,719 fork)batch import
affects ABIgood first issueimprovementstandard libraryswift evolution proposal needed

仓库指标

Star
 (69,989 star)
PR 合并指标
 (平均合并 8天 17小时) (30 天内合并 510 个 PR)

描述

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.

贡献者指南