As other participants have already pointed out, strlen(s) is called several times because it is in a condition, implying that it must be cached and reused.
But strlen(s) doesn't have to be called at all! s is (or implicitly converted) to a nul-terminated char array, since this is what strlen expects. Therefore, we can simply use this property for our own cycle.
void lower(zstring s) { for (char *p = s; *p; ++p) *p = std::tolower((unsigned char)*p); }
Quentin
source share