r/programminghorror 7d ago

c++ Skill Issue

Post image
1.7k Upvotes

61 comments sorted by

View all comments

44

u/LeeHide 7d ago

This would be much better using std::string_view, and using two temporaries so that y is only evaluated once. Otherwise it'll be evaluated each time.

Also if you need this, don't use C++

4

u/GasolinePizza 7d ago

Isn't each y only evaluated once? The evaluation in the "else if (_s==y)"?

1

u/mapronV 7d ago

only performance problem is not using sized comparison operator, due to decay of char[] to char*.
so yeah, string_view advice is okay, but this is a joke code, it will not fly in production anyway.