>>>>> "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.
False.
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.
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.
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
>> 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_ '-'.
Maybe. But I want to hear the Lua Team.
Ranier Vilela