我发现在iOS 13中更改了class_getMethodImplementation方法。
这是iOS 13中的代码:
libobjc.A.dylib`class_getMethodImplementation:
-> 0x1b6f70a80 <+0>: mov x2,x0
0x1b6f70a84 <+4>: mov x0,#0x0
0x1b6f70a88 <+8>: cbz x2,0x1b6f70ab8 ; <+56>
0x1b6f70a8c <+12>: cbz x1,0x1b6f70ab8 ; <+56>
0x1b6f70a90 <+16>: stp x29,x30,[sp,#-0x10]!
0x1b6f70a94 <+20>: mov x29,sp
0x1b6f70a98 <+24>: orr w3,wzr,#0xf
0x1b6f70a9c <+28>: mov x0,#0x0
0x1b6f70aa0 <+32>: bl 0x1b6f80250 ; lookUpImpOrForward
0x1b6f70aa4 <+36>: adrp x8,-2
0x1b6f70aa8 <+40>: add x8,x8,#0x580 ; =0x580
0x1b6f70aac <+44>: cmp x0,#0x0 ; =0x0
0x1b6f70ab0 <+48>: csel x0,x0,eq
0x1b6f70ab4 <+52>: ldp x29,[sp],#0x10
0x1b6f70ab8 <+56>: ret
,其他iOS版本中的代码为:
libobjc.A.dylib`class_getMethodImplementation:
-> 0x18457a8c4 <+0>: mov x8,#0x0
0x18457a8c8 <+4>: cbz x0,0x18457a900 ; <+60>
0x18457a8cc <+8>: cbz x1,0x18457a900 ; <+60>
0x18457a8d0 <+12>: stp x29,#-0x10]!
0x18457a8d4 <+16>: mov x29,sp
0x18457a8d8 <+20>: orr w3,#0x1
0x18457a8dc <+24>: orr w4,#0x1
0x18457a8e0 <+28>: orr w5,#0x1
0x18457a8e4 <+32>: mov x2,#0x0
0x18457a8e8 <+36>: bl 0x184585390 ; lookUpImpOrNil
0x18457a8ec <+40>: adrp x8,22
0x18457a8f0 <+44>: add x8,#0x5e0 ; =0x5e0
0x18457a8f4 <+48>: cmp x0,#0x0 ; =0x0
0x18457a8f8 <+52>: csel x8,eq
0x18457a8fc <+56>: ldp x29,#0x10
0x18457a900 <+60>: mov x0,x8
0x18457a904 <+64>: ret
,源代码是:
IMP class_getMethodImplementation(Class cls,SEL sel)
{
IMP imp;
if (!cls || !sel) return nil;
imp = lookUpImpOrNil(cls,sel,nil,YES/*initialize*/,YES/*cache*/,YES/*resolver*/);
// Translate forwarding function to C-callable external version
if (!imp) {
return _objc_msgForward;
}
return imp;
}
为什么会有这样的变化,从而使运行效率更高?