lua-users home
lua-l archive

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


>>>>> "Ranier" == Ranier Vilela <ranier.vf@gmail.com> writes:

 Ranier> But if that is really the case, it is simple to resolve and
 Ranier> continue to avoid calling strlen over and over again.

strcmp doesn't call strlen (in reasonable implementations) and strncmp
isn't necessarily any faster. Trying to prefer strncmp over strcmp leads
to less obvious and more error-prone code.

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

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

 Ranier> Standardization.

lua_pushliteral used to do this optimization, so if it _were_ worth it,
then it would be simple to just use lua_pushliteral in place of
lua_pushstring. But given that recent lua versions expand
lua_pushliteral as just lua_pushstring, it's clearly not worth it.

Your approach is strictly worse than either, by having the programmer
explicitly supply a value that the compiler or library can find out for
itself.

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

 >> It also does something completely different, which is not applicable
 >> here.

 Ranier> Basically, it does a search for '-',

No, the code in question is testing whether the argument (filename) is
_exactly equal to_ "-", not whether it _contains_ '-'.

-- 
Andrew.