@@ -3744,10 +3744,10 @@ fileprivate func dynamicLibraryAddress<Base, Leaf>(
3744
3744
3745
3745
@available ( SwiftStdLib 5 . 7 , * )
3746
3746
extension AnyKeyPath : CustomDebugStringConvertible {
3747
-
3747
+
3748
3748
@available ( SwiftStdLib 5 . 7 , * )
3749
3749
public var debugDescription : String {
3750
- #if SWIFT_ENABLE_REFLECTION
3750
+ #if SWIFT_ENABLE_REFLECTION
3751
3751
var description = " \\ \( String ( describing: Self . rootType) ) "
3752
3752
return withBuffer {
3753
3753
var buffer = $0
@@ -3759,83 +3759,57 @@ extension AnyKeyPath: CustomDebugStringConvertible {
3759
3759
let ( rawComponent, optNextType) = buffer. next ( )
3760
3760
let hasEnded = optNextType == nil
3761
3761
let nextType = optNextType ?? Self . valueType
3762
- func name( for offset: Int ) -> String {
3762
+ switch rawComponent. value {
3763
+ case . optionalForce, . optionalWrap, . optionalChain:
3764
+ break
3765
+ default :
3766
+ description. append ( " . " )
3767
+ }
3768
+ switch rawComponent. value {
3769
+ case . class( let offset) ,
3770
+ . struct( let offset) :
3763
3771
let count = _getRecursiveChildCount ( valueType)
3764
- for i in 0 ..< count {
3765
- if _getChildOffset (
3766
- valueType,
3767
- index: i
3768
- ) == offset {
3769
- var field = _FieldReflectionMetadata ( )
3770
- _ = _getChildMetadata (
3772
+ let index = ( 0 ..< count)
3773
+ . first ( where: { i in
3774
+ _getChildOffset (
3771
3775
valueType,
3772
- index: i,
3773
- fieldMetadata: & field
3774
- )
3775
- defer {
3776
- field. freeFunc ? ( field. name)
3777
- }
3778
- return String ( cString: field. name)
3776
+ index: i
3777
+ ) == offset
3778
+ } )
3779
+ if let index = index {
3780
+ var field = _FieldReflectionMetadata ( )
3781
+ _ = _getChildMetadata (
3782
+ valueType,
3783
+ index: index,
3784
+ fieldMetadata: & field
3785
+ )
3786
+ defer {
3787
+ field. freeFunc ? ( field. name)
3779
3788
}
3789
+ description. append ( String ( cString: field. name) )
3790
+ } else {
3791
+ description. append ( " <offset \( offset) ( \( nextType) )> " )
3780
3792
}
3781
- return " <offset \( offset) ( \( nextType) )> "
3782
- }
3783
- func name(
3784
- for pointer: ComputedAccessorsPtr ,
3785
- base: Any . Type ,
3786
- leaf: Any . Type
3787
- ) -> String {
3793
+ case . get( _, let accessors, _) ,
3794
+ . nonmutatingGetSet( _, let accessors, _) ,
3795
+ . mutatingGetSet( _, let accessors, _) :
3788
3796
func project< Base> ( base: Base . Type ) -> String {
3789
3797
func project2< Leaf> ( leaf: Leaf . Type ) -> String {
3790
3798
dynamicLibraryAddress (
3791
- of: pointer ,
3799
+ of: accessors ,
3792
3800
base,
3793
3801
leaf
3794
3802
)
3795
3803
}
3796
3804
return _openExistential ( nextType, do: project2)
3797
3805
}
3798
- return _openExistential ( base, do: project)
3799
- }
3800
- switch rawComponent. value {
3801
- case . optionalForce, . optionalWrap, . optionalChain:
3802
- break
3803
- default :
3804
- description. append ( " . " )
3805
- }
3806
- switch rawComponent. value {
3807
- case . class( let offset) :
3808
- description. append ( name ( for: offset) )
3809
- case . get( _, let accessors, _) :
3810
3806
description. append (
3811
- name (
3812
- for: accessors,
3813
- base: valueType,
3814
- leaf: nextType
3815
- )
3816
- )
3817
- case . mutatingGetSet( _, let accessors, _) :
3818
- description. append (
3819
- name (
3820
- for: accessors,
3821
- base: valueType,
3822
- leaf: nextType
3823
- )
3824
- )
3825
- case . nonmutatingGetSet( _, let accessors, _) :
3826
- description. append (
3827
- name (
3828
- for: accessors,
3829
- base: valueType,
3830
- leaf: nextType
3831
- )
3807
+ _openExistential ( valueType, do: project)
3832
3808
)
3833
3809
case . optionalChain, . optionalWrap:
3834
3810
description. append ( " ? " )
3835
3811
case . optionalForce:
3836
3812
description. append ( " ! " )
3837
- case . struct( let offset) :
3838
- description. append ( name ( for: offset) )
3839
3813
}
3840
3814
if hasEnded {
3841
3815
break
0 commit comments