|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 |
| -@usableFromInline |
14 |
| -internal protocol _HasContiguousBytes { |
15 |
| - func withUnsafeBytes<R>( |
16 |
| - _ body: (UnsafeRawBufferPointer) throws -> R |
17 |
| - ) rethrows -> R |
18 |
| - |
19 |
| - var _providesContiguousBytesNoCopy: Bool { get } |
20 |
| -} |
21 |
| -extension _HasContiguousBytes { |
22 |
| - @inlinable |
23 |
| - var _providesContiguousBytesNoCopy: Bool { |
24 |
| - @inline(__always) get { return true } |
25 |
| - } |
26 |
| -} |
27 |
| -extension Array: _HasContiguousBytes { |
28 |
| - @inlinable |
29 |
| - var _providesContiguousBytesNoCopy: Bool { |
30 |
| - @inline(__always) get { |
31 |
| -#if _runtime(_ObjC) |
32 |
| - return _buffer._isNative |
33 |
| -#else |
34 |
| - return true |
35 |
| -#endif |
36 |
| - } |
37 |
| - } |
38 |
| -} |
39 |
| -extension ContiguousArray: _HasContiguousBytes {} |
40 |
| -extension UnsafeBufferPointer: _HasContiguousBytes { |
41 |
| - @inlinable @inline(__always) |
42 |
| - func withUnsafeBytes<R>( |
43 |
| - _ body: (UnsafeRawBufferPointer) throws -> R |
44 |
| - ) rethrows -> R { |
45 |
| - let ptr = UnsafeRawPointer(self.baseAddress._unsafelyUnwrappedUnchecked) |
46 |
| - let len = self.count &* MemoryLayout<Element>.stride |
47 |
| - return try body(UnsafeRawBufferPointer(start: ptr, count: len)) |
48 |
| - } |
49 |
| -} |
50 |
| -extension UnsafeMutableBufferPointer: _HasContiguousBytes { |
51 |
| - @inlinable @inline(__always) |
52 |
| - func withUnsafeBytes<R>( |
53 |
| - _ body: (UnsafeRawBufferPointer) throws -> R |
54 |
| - ) rethrows -> R { |
55 |
| - let ptr = UnsafeRawPointer(self.baseAddress._unsafelyUnwrappedUnchecked) |
56 |
| - let len = self.count &* MemoryLayout<Element>.stride |
57 |
| - return try body(UnsafeRawBufferPointer(start: ptr, count: len)) |
58 |
| - } |
59 |
| -} |
60 |
| -extension UnsafeRawBufferPointer: _HasContiguousBytes { |
61 |
| - @inlinable @inline(__always) |
62 |
| - func withUnsafeBytes<R>( |
63 |
| - _ body: (UnsafeRawBufferPointer) throws -> R |
64 |
| - ) rethrows -> R { |
65 |
| - return try body(self) |
66 |
| - } |
67 |
| -} |
68 |
| -extension UnsafeMutableRawBufferPointer: _HasContiguousBytes { |
69 |
| - @inlinable @inline(__always) |
70 |
| - func withUnsafeBytes<R>( |
71 |
| - _ body: (UnsafeRawBufferPointer) throws -> R |
72 |
| - ) rethrows -> R { |
73 |
| - return try body(UnsafeRawBufferPointer(self)) |
74 |
| - } |
75 |
| -} |
76 | 13 | extension String {
|
77 | 14 |
|
78 | 15 | @inlinable @inline(__always)
|
|
0 commit comments