>>>>> "Ranier" == Ranier Vilela <firstname.lastname@example.org> 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.
Strncmp always is faster.
Once strcmp, it will go to the end of the string, always.
Trying to prefer strncmp over strcmp leads
to less obvious and more error-prone code.
Good reason to go slow, like a turtle.
Ranier> - lua_pushstring(L, "k");
Ranier> + lua_pushlstring(L, "k", 1);
>> This really isn't likely to be worth it.
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
So, why did they implement lua_pushlstring?
Perhaps not to be used.
Ranier> Strchr is it's more efficient than strcmp.
>> It also does something completely different, which is not applicable
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_ '-'.
Maybe. But I want to hear the Lua Team.