-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[stdlib] Add ContiguousCollection #23616
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,74 @@ | ||||||
//===----------------------------------------------------------------------===// | ||||||
// | ||||||
// This source file is part of the Swift.org open source project | ||||||
// | ||||||
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors | ||||||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||||||
// | ||||||
// See https://swift.org/LICENSE.txt for license information | ||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||||||
// | ||||||
//===----------------------------------------------------------------------===// | ||||||
|
||||||
/// A collection that supports access to its underlying contiguous storage. | ||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
public protocol ContiguousCollection: Collection | ||||||
where SubSequence: ContiguousCollection { | ||||||
/// Calls a closure with a pointer to the array's contiguous storage. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Remove: |
||||||
func withUnsafeBufferPointer<R>( | ||||||
_ body: (UnsafeBufferPointer<Element>) throws -> R | ||||||
) rethrows -> R | ||||||
} | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
public extension ContiguousCollection { | ||||||
@inlinable | ||||||
func withUnsafeBufferPointer<R>( | ||||||
_ body: (UnsafeBufferPointer<Element>) throws -> R | ||||||
) rethrows -> R { | ||||||
return try withContiguousStorageIfAvailable(body)! | ||||||
} | ||||||
} | ||||||
|
||||||
/// A collection that supports mutable access to its underlying contiguous | ||||||
/// storage. | ||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
public protocol MutableContiguousCollection: ContiguousCollection, MutableCollection | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap to 80 characters? |
||||||
where SubSequence: MutableContiguousCollection { | ||||||
/// Calls the given closure with a pointer to the array's mutable contiguous | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Remove: |
||||||
/// storage. | ||||||
mutating func withUnsafeMutableBufferPointer<R>( | ||||||
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R | ||||||
) rethrows -> R | ||||||
} | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
extension MutableContiguousCollection { | ||||||
@inlinable | ||||||
public mutating func withUnsafeMutableBufferPointer<R>( | ||||||
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R | ||||||
) rethrows -> R { | ||||||
return try withContiguousMutableStorageIfAvailable(body)! | ||||||
} | ||||||
} | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
extension Array: MutableContiguousCollection { } | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
extension ContiguousArray: MutableContiguousCollection { } | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
extension ArraySlice: MutableContiguousCollection { } | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
extension UnsafeBufferPointer: ContiguousCollection { } | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
extension UnsafeMutableBufferPointer: MutableContiguousCollection { } | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
extension Slice: ContiguousCollection where Base: ContiguousCollection { } | ||||||
|
||||||
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *) | ||||||
extension Slice: MutableContiguousCollection where Base: MutableContiguousCollection { } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap to 80 characters? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OSX
=>macOS
(11 times) and in same order as rest of stdlib, for easier find and replace.