Closed stephenberry closed 2 years ago
You are totally right, the calls to strlen
could be easily avoided! However, as mentioned in the previous issue, I would rather add a member to Identifier
to store the string size (mNameSize
?), at least for the time being.
Storing the string size in identifiers.
I noted in my first issue concerning macros my desire and recommendation to move to C++17 for cleaner and faster code. One motivation is the inclusion of
std::string_view
. It's a simple class, but using it instead ofconst char*
in some places it will bring significant performance improvements.Using
std::string_view
will allow you to avoid callingstrlen
in a lot of places, and instead directly get the size. For example,mName
inIdentifier
should be a string_view.strlen
has to iterate through the characters of the string, making it expensive to call constantly, like infindFirstSeparator
.You could obviously write your own simple string_view class to maintain C++11 compliance, but there are a number of additional reasons to move to C++17, and I think it's best to aim to keep the code base as simple and minimal as possible by using the standard library.