Re:Effortless Performance Improvements in C++: std:vector
by jeffbee on Wednesday March 08, 2023 @05:14PM
(#35075495)
That's just strtok, and programming C++ as if you are an unreformed C programmer is always a mistake. If you want to not copy the strings, string_view. We also have std::split and std::views::split etc.
Re:Effortless Performance Improvements in C++: std:vector
by jstimpfle on Wednesday March 08, 2023 @06:28PM
(#35076210)
To prevent any misunderstandings, programming C using strtok is a mistake too.
Re:Effortless Performance Improvements in C++: std:vector
by jstimpfle on Wednesday March 08, 2023 @06:26PM
(#35076191)
As a general rule, don't overwrite your input data. That's a hardcore space optimization that can end up making your program slower. At the minimum it will lead to headaches later on. Are you sure you won't need the pristine input for diagnostic and error messages later on? Do you always have at least 1 separator character to overwrite in the first place?
Of course, as that post suggests, use reserve() to encourage having the vector itself as optimal as possible. (In my strsplit call I pass it in as optional so each caller can optimize it).