10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- /// A collection that supports access to its underlying contiguous storage.
13
+ /// An object composed of count elements that are stored contiguously in memory.
14
+ ///
15
+ /// In practice, most types conforming to this protocol will be Collections,
16
+ /// but they need not be--they need only have an Element type and count, and
17
+ /// provide the withUnsafeBufferPointer function.
14
18
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
15
- public protocol _ContiguousCollection : Collection
16
- where SubSequence: _ContiguousCollection {
17
- /// Calls a closure with a pointer to the array's contiguous storage.
19
+ public protocol AccelerateBuffer {
20
+ /// The buffer's element type.
21
+ associatedtype Element
22
+ /// The number of elements in the buffer.
23
+ var count : Int { get }
24
+ /// Calls a closure with a pointer to the object's contiguous storage.
18
25
func withUnsafeBufferPointer< R> (
19
26
_ body: ( UnsafeBufferPointer < Element > ) throws -> R
20
27
) rethrows -> R
21
28
}
22
29
30
+ /// A mutable object composed of count elements that are stored contiguously
31
+ /// in memory.
32
+ ///
33
+ /// In practice, most types conforming to this protocol will be
34
+ /// MutableCollections, but they need not be.
23
35
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
24
- public extension _ContiguousCollection {
25
- func withUnsafeBufferPointer< R> (
26
- _ body: ( UnsafeBufferPointer < Element > ) throws -> R
27
- ) rethrows -> R {
28
- return try withContiguousStorageIfAvailable ( body) !
29
- }
30
- }
31
-
32
- /// A collection that supports mutable access to its underlying contiguous
33
- /// storage.
34
- @available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
35
- public protocol _MutableContiguousCollection : _ContiguousCollection , MutableCollection
36
- where SubSequence: _MutableContiguousCollection {
36
+ public protocol MutableAccelerateBuffer : AccelerateBuffer {
37
37
/// Calls the given closure with a pointer to the array's mutable contiguous
38
38
/// storage.
39
39
mutating func withUnsafeMutableBufferPointer< R> (
@@ -42,7 +42,16 @@ where SubSequence: _MutableContiguousCollection {
42
42
}
43
43
44
44
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
45
- extension _MutableContiguousCollection {
45
+ public extension AccelerateBuffer where Self: Collection {
46
+ func withUnsafeBufferPointer< R> (
47
+ _ body: ( UnsafeBufferPointer < Element > ) throws -> R
48
+ ) rethrows -> R {
49
+ return try withContiguousStorageIfAvailable ( body) !
50
+ }
51
+ }
52
+
53
+ @available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
54
+ extension MutableAccelerateBuffer where Self: MutableCollection {
46
55
public mutating func withUnsafeMutableBufferPointer< R> (
47
56
_ body: ( inout UnsafeMutableBufferPointer < Element > ) throws -> R
48
57
) rethrows -> R {
@@ -51,22 +60,22 @@ extension _MutableContiguousCollection {
51
60
}
52
61
53
62
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
54
- extension Array : _MutableContiguousCollection { }
63
+ extension Array : MutableAccelerateBuffer { }
55
64
56
65
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
57
- extension ContiguousArray : _MutableContiguousCollection { }
66
+ extension ContiguousArray : MutableAccelerateBuffer { }
58
67
59
68
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
60
- extension ArraySlice : _MutableContiguousCollection { }
69
+ extension ArraySlice : MutableAccelerateBuffer { }
61
70
62
71
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
63
- extension UnsafeBufferPointer : _ContiguousCollection { }
72
+ extension UnsafeBufferPointer : AccelerateBuffer { }
64
73
65
74
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
66
- extension UnsafeMutableBufferPointer : _MutableContiguousCollection { }
75
+ extension UnsafeMutableBufferPointer : MutableAccelerateBuffer { }
67
76
68
77
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
69
- extension Slice : _ContiguousCollection where Base: _ContiguousCollection { }
78
+ extension Slice : AccelerateBuffer where Base: Collection { }
70
79
71
80
@available ( iOS 9999 , OSX 9999 , tvOS 9999 , watchOS 9999 , * )
72
- extension Slice : _MutableContiguousCollection where Base: _MutableContiguousCollection { }
81
+ extension Slice : MutableAccelerateBuffer where Base: MutableCollection { }
0 commit comments