Search code examples
hookaprapache-portable-runtime

Is APR(Apache Portable Runtime) hook efficient?


I want to implement function_A by using APR hook ,but I wonder if it is efficient. Does anyone use APR hook or know the working principle?And it will be good if any detail figures or data is shown.

Thank you very much!


Solution

  • APR hooks are very efficient, the invocation of the hook is a macro that expands to looping over an array of function pointers and calling them.

    #define APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(ns,link,ret,name,args_decl,args_use,decline) \
    APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
    link##_DECLARE(ret) ns##_run_##name args_decl \
        { \
        ns##_LINK_##name##_t *pHook; \
        int n; \
        ret rv; \
    \
        if(!_hooks.link_##name) \
            return decline; \
    \
        pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
        for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
            { \
            rv=pHook[n].pFunc args_use; \
    \
            if(rv != decline) \
                return rv; \
            } \
        return decline; \
        }
    

    So there is really no reason to avoid them from a performance perspective.