lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, May 19, 2020 at 5:01 PM Sean Conner <sean@conman.org> wrote:
>
>   I think it would be a bit faster if it was:
>
>         if (L->globalhook != NULL)
>           (*L->globalhook)(L);
>
>   That way, it avoids the overhead of a function call.
>
>   -spc

That's dangerous as written, because it could get changed to be NULL
in between when you check it and when you call it. You'd need to do
this instead:

    lua_GlobalHook gh = L->globalhook;
    if(gh != NULL)
      (*gh)(L);

Having said that, I agree that'd be a lot faster, since indirect calls
are pretty slow, and usually there won't be a global hook. One other
note, though: to fix the coroutine issue, I was planning to put
globalhook in G(L) instead of in L.

Joseph C. Sible