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-11957] withContiguous[Mutable]StorageIfAvailable not implemented on Slice #54377

Closed
stephentyrone opened this issue Dec 16, 2019 · 5 comments
Assignees
Labels
feature A feature request or implementation standard library Area: Standard library umbrella

Comments

@stephentyrone
Copy link
Member

Previous ID SR-11957
Radar rdar://58090587
Original Reporter @stephentyrone
Type New Feature
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels New Feature
Assignee @lorentey
Priority Medium

md5: 1e0512ad7793abdadd029d3398408f86

Issue Description:

Slice does not implement withContiguous[Mutable]StorageIfAvailable, which means it falls to the default implementation which, unconditionally nil s out, even when Base does provide a custom implementation.

This is most noticeable with Unsafe[Mutable]BufferPointer:

var a = UnsafeMutableBufferPointer<Int>.allocate(capacity: 4)
a[1...].withContiguousStorageIfAvailable { print($0) } // does not print

Providing a good implementation on Slice is somewhat tricky because we are lacking constraints on the index type of Base, but it would be nice to improve this.

@stephentyrone
Copy link
Member Author

Note for anyone hitting this: you can always work around it by slicing the UnsafeMutableBufferPointer passed to the closure instead, though that's not as ergonomic in all cases.

@stephentyrone
Copy link
Member Author

@swift-ci create

1 similar comment
@lorentey
Copy link
Member

@swift-ci create

@lorentey
Copy link
Member

I think it's okay to just rely on Collection.distance(from:to🙂 to get the offsets.

@lorentey
Copy link
Member

#28883

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation and removed new feature labels Feb 4, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants