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
strlen is calculated at every iteration of the loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With