File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -408,15 +408,22 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
408
408
@_transparent nonmutating set {
409
409
// Autorelease the object reference.
410
410
typealias OptionalAnyObject = AnyObject ?
411
- Builtin . retain ( unsafeBitCast ( newValue, to: OptionalAnyObject . self) )
412
- Builtin . autorelease ( unsafeBitCast ( newValue, to: OptionalAnyObject . self) )
411
+ let newAnyObject = unsafeBitCast ( newValue, to: OptionalAnyObject . self)
412
+ Builtin . retain ( newAnyObject)
413
+ Builtin . autorelease ( newAnyObject)
413
414
// Trivially assign it as an OpaquePointer; the pointer references an
414
415
// autoreleasing slot, so retains/releases of the original value are
415
416
// unneeded.
416
- typealias OptionalOpaquePointer = OpaquePointer ?
417
- let p = UnsafeMutablePointer < OptionalOpaquePointer > (
418
- UnsafeMutablePointer < Pointee > ( self ) )
419
- p. pointee = unsafeBitCast ( newValue, to: OptionalOpaquePointer . self)
417
+ typealias OptionalUnmanaged = Unmanaged < AnyObject > ?
418
+ UnsafeMutablePointer < Pointee > ( _rawValue) . withMemoryRebound (
419
+ to: OptionalUnmanaged . self, capacity: 1 ) {
420
+ if let newAnyObject = newAnyObject {
421
+ $0. pointee = Unmanaged . passUnretained ( newAnyObject)
422
+ }
423
+ else {
424
+ $0. pointee = nil
425
+ }
426
+ }
420
427
}
421
428
}
422
429
You can’t perform that action at this time.
0 commit comments