Search code examples
c++cpp-core-guidelines

What is wasted in this example from the Cpp Core Guidelines?


What is wasted in the example from the Cpp Core Guidelines?

P.9: Don't waste time or space

[...]

void lower(zstring s)
{
    for (int i = 0; i < strlen(s); ++i) s[i] = tolower(s[i]);
}

Yes, this is an example from production code. We leave it to the reader to figure out what's wasted.

from https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rp-waste


Solution

  • strlen is calculated at every iteration of the loop.