@@ -38,22 +38,27 @@ internal func _collectAllReferencesInsideObjectImpl(
38
38
let count = mirror. children. count
39
39
40
40
let id : ObjectIdentifier ?
41
- let toAnyObject : AnyObject ?
41
+ let ref : UnsafeRawPointer ?
42
42
if type ( of: value) is AnyObject . Type {
43
43
// Object is a class (but not an ObjC-bridged struct)
44
- toAnyObject = _unsafeDowncastToAnyObject ( fromAny: value)
45
- id = ObjectIdentifier ( toAnyObject!)
46
- } else if type ( of: value) is Builtin . BridgeObject. Type ||
47
- type ( of: value) is Builtin . NativeObject. Type {
48
- toAnyObject = _unsafeDowncastToAnyObject ( fromAny: value)
49
- id = ObjectIdentifier ( toAnyObject!)
44
+ let toAnyObject = _unsafeDowncastToAnyObject ( fromAny: value)
45
+ ref = UnsafeRawPointer ( Unmanaged . passUnretained ( toAnyObject) . toOpaque ( ) )
46
+ id = ObjectIdentifier ( toAnyObject)
47
+ } else if type ( of: value) is Builtin . BridgeObject . Type {
48
+ ref = UnsafeRawPointer (
49
+ Builtin . bridgeToRawPointer ( value as! Builtin . BridgeObject ) )
50
+ id = nil
51
+ } else if type ( of: value) is Builtin . NativeObject . Type {
52
+ ref = UnsafeRawPointer (
53
+ Builtin . bridgeToRawPointer ( value as! Builtin . NativeObject ) )
54
+ id = nil
50
55
} else if let metatypeInstance = value as? Any . Type {
51
56
// Object is a metatype
52
57
id = ObjectIdentifier ( metatypeInstance)
53
- toAnyObject = nil
58
+ ref = nil
54
59
} else {
55
60
id = nil
56
- toAnyObject = nil
61
+ ref = nil
57
62
}
58
63
59
64
if let theId = id {
@@ -67,9 +72,8 @@ internal func _collectAllReferencesInsideObjectImpl(
67
72
}
68
73
69
74
// If it is a reference, add it to the result.
70
- if let toAnyObject = toAnyObject {
71
- references. append (
72
- UnsafeRawPointer ( Unmanaged . passUnretained ( toAnyObject) . toOpaque ( ) ) )
75
+ if let ref = ref {
76
+ references. append ( ref)
73
77
}
74
78
75
79
// Recursively visit the children of the current value.
0 commit comments