File tree Expand file tree Collapse file tree 2 files changed +3
-23
lines changed Expand file tree Collapse file tree 2 files changed +3
-23
lines changed Original file line number Diff line number Diff line change @@ -749,19 +749,7 @@ extension Unsafe${Mutable}BufferPointer {
749
749
to type: T . Type,
750
750
_ body: ( ${ Self} < T> ) throws -> Result
751
751
) rethrows -> Result {
752
- if let base = _position {
753
- _debugPrecondition ( MemoryLayout< Element> . stride == MemoryLayout< T> . stride)
754
- Builtin . bindMemory ( base. _rawValue, count. _builtinWordValue, T . self)
755
- defer {
756
- Builtin . bindMemory ( base. _rawValue, count. _builtinWordValue, Element . self)
757
- }
758
-
759
- return try body ( ${ Self} < T> (
760
- start: Unsafe ${ Mutable} Pointer< T> ( base. _rawValue) , count: count) )
761
- }
762
- else {
763
- return try body ( ${ Self} < T> ( start: nil , count: 0 ) )
764
- }
752
+ return try withMemoryRebound ( to: T . self, body)
765
753
}
766
754
767
755
/// A pointer to the first element of the buffer.
Original file line number Diff line number Diff line change @@ -333,11 +333,7 @@ public struct UnsafePointer<Pointee>: _Pointer {
333
333
capacity count: Int ,
334
334
_ body: ( UnsafePointer < T > ) throws -> Result
335
335
) rethrows -> Result {
336
- Builtin . bindMemory ( _rawValue, count. _builtinWordValue, T . self)
337
- defer {
338
- Builtin . bindMemory ( _rawValue, count. _builtinWordValue, Pointee . self)
339
- }
340
- return try body ( . init( _rawValue) )
336
+ return try withMemoryRebound ( to: T . self, capacity: count, body)
341
337
}
342
338
343
339
/// Accesses the pointee at the specified offset from this pointer.
@@ -1022,11 +1018,7 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
1022
1018
capacity count: Int ,
1023
1019
_ body: ( UnsafeMutablePointer < T > ) throws -> Result
1024
1020
) rethrows -> Result {
1025
- Builtin . bindMemory ( _rawValue, count. _builtinWordValue, T . self)
1026
- defer {
1027
- Builtin . bindMemory ( _rawValue, count. _builtinWordValue, Pointee . self)
1028
- }
1029
- return try body ( . init( _rawValue) )
1021
+ return try withMemoryRebound ( to: T . self, capacity: count, body)
1030
1022
}
1031
1023
1032
1024
/// Accesses the pointee at the specified offset from this pointer.
You can’t perform that action at this time.
0 commit comments