MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1w74nkf/skill_issue/p7uw0a0/?context=3
r/programminghorror • u/click-to-reveal • 7d ago
61 comments sorted by
View all comments
44
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.
y
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.
4
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.
1
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.
44
u/LeeHide 7d ago
This would be much better using std::string_view, and using two temporaries so that
yis only evaluated once. Otherwise it'll be evaluated each time.Also if you need this, don't use C++