zoukankan      html  css  js  c++  java
  • runtime中的宏定义解释表

    #define fastpath(x) (__builtin_expect(bool(x), 1))

    #define slowpath(x) (__builtin_expect(bool(x), 0))

    /**

     这个指令是gcc引入的,作用是允许程序员将最有可能执行的分支告诉编译器。这个指令的写法为:__builtin_expect(EXP, N)。

     意思是:EXP==N的概率很大。

     */

     int methodListIsFixedUp = mlist->isFixedUp();
        int methodListHasExpectedSize = mlist->entsize() == sizeof(method_t);
        //fastpath ,表示条件值为1的可能性很大,即很有可能执行if后面的 renturn语句,slowpath则是很有可能执行else里面的语句
        if (fastpath(methodListIsFixedUp && methodListHasExpectedSize)) {
            return findMethodInSortedMethodList(sel, mlist);
        } else {
            // Linear search of unsorted method list
            for (auto& meth : *mlist) {
                if (meth.name == sel) return &meth;
            }
        }

    使用fastpath(),执行 if 后面的语句的机会更大,使用 slowpath(),执行 else 后面的语句的机会更大。通过这种方式,编译器在编译过程中,会将可能性更大的代码紧跟着起面的代码,从而减少指令跳转带来的性能上的下降。

     
  • 相关阅读:
    JavaScript 面向对象
    javascript中this的指向
    销售
    Java垃圾回收机制
    判断浏览器是否缩放
    pattern space and hold space of sed
    语言基础
    Python中PyQuery库的使用总结
    多个计数器在Vuex中的状态
    Sklearn
  • 原文地址:https://www.cnblogs.com/vkSwift/p/13971891.html
Copyright © 2011-2022 走看看