iOS底层系列04 -- 编译器的优化

2021-02-04  本文已影响0人  YanZi_33

slowpathfastpath的宏定义如下:

#define fastpath(x) (__builtin_expect(bool(x), 1))
#define slowpath(x) (__builtin_expect(bool(x), 0))
if (x) {
   return 1;
}else{
   return 0;
}
if (!x) {
   return 0;
}else{
   return 1;
}
long __builtin_expect (long EXP, long C)
//x = !cls->ISA()->hasCustomAWZ() 为真的概率更大 执行if中的语句
if (fastpath(!cls->ISA()->hasCustomAWZ())) {
   return _objc_rootAllocWithZone(cls, nil);
}
//x = checkNil && !cls 为假的概率更大 执行else中的语句
if (slowpath(checkNil && !cls)) return nil;
上一篇 下一篇

猜你喜欢

热点阅读