About macro `isvalid` in Lua5.4(work2)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

About macro `isvalid` in Lua5.4(work2)

重归混沌
When I read the Lua5.4(work2) source code, change of `isvalid`(https://github.com/lua/lua/blob/b95e46621873cfb460e1d11dcd153914d5d69f86/lapi.c#L42) confused me.

In my opinion, `ttisnil(&G(L)->nilvalue)` is always true, `(!ttisnil(o) || o != &G(L)->nilvalue)` can be simplied to `(o != &(G)->nilvalue)`.

Of course  Roberto is always right. But I can't find my mistake.

It confused me for sereval days.  
Reply | Threaded
Open this post in threaded view
|

Re: About macro `isvalid` in Lua5.4(work2)

云风 Cloud Wu


重归混沌 <[hidden email]>于2018年8月31日周五 上午9:31写道:
When I read the Lua5.4(work2) source code, change of `isvalid`(https://github.com/lua/lua/blob/b95e46621873cfb460e1d11dcd153914d5d69f86/lapi.c#L42) confused me.

In my opinion, `ttisnil(&G(L)->nilvalue)` is always true, `(!ttisnil(o) || o != &G(L)->nilvalue)` can be simplied to `(o != &(G)->nilvalue)`.

Of course  Roberto is always right. But I can't find my mistake.

It confused me for sereval days.  

I guess !ttisnil(o) is cheaper than o != &(G)->nilvalue .
Reply | Threaded
Open this post in threaded view
|

Re: About macro `isvalid` in Lua5.4(work2)

Roberto Ierusalimschy
> > In my opinion, `ttisnil(&G(L)->nilvalue)` is always true, `(!ttisnil(o) ||
> > o != &G(L)->nilvalue)` can be simplied to `(o != &(G)->nilvalue)`.
> >
> > Of course  Roberto is always right. But I can't find my mistake.
> >
> > It confused me for sereval days.
> >
>
> I guess !ttisnil(o) is cheaper than o != &(G)->nilvalue .

That is right. !ttisnil(o) is cheaper and cover the most common cases.
I will add a comment about that in the source.

-- Roberto