lua-users home
lua-l archive

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


Em dom., 15 de nov. de 2020 às 22:17, Andrew Gierth <andrew@tao11.riddles.org.uk> escreveu:
>>>>> "Ranier" == Ranier Vilela <ranier.vf@gmail.com> writes:

 Ranier> -  if (strcmp(ar.namewhat, "method") == 0) {
 Ranier> +  if (strncmp(ar.namewhat, "method", 6) == 0) {

That's obviously completely wrong, since it would then match any string
_starting with_ "method".
I still want to hear the Lua Team.
But if that is really the case, it is simple to resolve and continue to avoid calling strlen over and over again.
+if (strncmp(ar.namewhat, "method\0", 7) == 0) {


All your other examples of strncmp are wrong for the same reason.
Same above.


 Ranier> 4. Avoid strlen at lua_pushstring, with a constant "k".

 Ranier> -    lua_pushstring(L, "k");
 Ranier> +    lua_pushlstring(L, "k", 1);

This really isn't likely to be worth it.
Standardization.


 Ranier> 5. fgets returns char * pointer which needs to be compared to
 Ranier> NULL, not 0.

0 is a valid way to say "the null pointer".
Really.
And that talks about NULL.
In addition, in Lua fgets it is used against NULL.
See at:
File lua.c:
         fgets (b, LUA_MAXINPUT, stdin)! = NULL) / * get line * /


 Ranier> Strchr is it's more efficient than strcmp.

It also does something completely different, which is not applicable
here.
Basically, it does a search for '-', which strchr is much more efficient.
In addition, strchr is used elsewhere in the code to do the same.

Ranier Vilela