Open dabrahams opened 4 years ago
https://github.com/dabrahams/DivideAndConquer demonstrates the bones of a solution. It's not refined, but it appears to work. Probably if we brought back the "pinned" bit it could be better used for this purpose.
@swift-ci create
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 1 | |Component/s | Compiler, Standard Library | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 09efd968f958e93863a1491ba05236dbIssue Description:
The appended program should print "0". Instead it prints "242".
The library was designed so we didn’t have to do the STL thing and pass pairs of iterators (Indexes) around to demarcate subranges we want to operate on. Instead you’re supposed to be able to say:
c[..<i].recursiveMutation()
c[i...].recursiveMutation()
The problem is that this causes COW. It shouldn’t as long as the mutation is only using
MutableCollection
operations, but it does. ARC needs to borrow ownership for the slicing operation and the mutation, but it does not.The result is that if you want to write any of these algorithms efficiently, you need to implement algorithms taking pairs of indices, and if you want to build a composable family of generic algorithms, you have to expose these APIs publicly.