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 后面的语句的机会更大。通过这种方式,编译器在编译过程中,会将可能性更大的代码紧跟着起面的代码,从而减少指令跳转带来的性能上的下降。

     
  • 相关阅读:
    docker 简单使用
    apache 目录网站显示indexs
    MySQL索引失效的几种情况
    mysql 基本常用语句
    UNIX 版本
    B语言的发明者 Ken Thomson & C语言的发明者Dennis Ritchie
    My SQl 积累
    C# DGV多行选择
    C#中很模糊查询DGV中数据的两种方法
    网址
  • 原文地址:https://www.cnblogs.com/vkSwift/p/13971891.html
Copyright © 2011-2022 走看看