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 {
749749 to type: T . Type,
750750 _ body: ( ${ Self} < T> ) throws -> Result
751751 ) 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)
765753 }
766754
767755 /// 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 {
333333 capacity count: Int ,
334334 _ body: ( UnsafePointer < T > ) throws -> Result
335335 ) 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)
341337 }
342338
343339 /// Accesses the pointee at the specified offset from this pointer.
@@ -1022,11 +1018,7 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
10221018 capacity count: Int ,
10231019 _ body: ( UnsafeMutablePointer < T > ) throws -> Result
10241020 ) 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)
10301022 }
10311023
10321024 /// Accesses the pointee at the specified offset from this pointer.
You can’t perform that action at this time.
0 commit comments