Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 267
hamster on wheels Avatar asked Oct 25 '16 19:10

hamster on wheels


Video Answer


1 Answers

strlen is calculated at every iteration of the loop.

like image 175
user31264 Avatar answered Oct 04 '22 19:10

user31264