-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring more consistency to nmodl::stringutils utility functions #1066
Comments
I didn’t check all usages but just want to say that « performance » aspect is not much a concern in the context of nmodl (as its translation program and strings that we manipulate here are hundreds of chars long). So I don’t have strong: something that make usage simpler, nicer, intuitive is fine. tagging @1uc as well as he has been looking at the code in recent weeks and would have opinion. Edit: Copying @1uc's comment from the Slack:
|
uff, I'm happy to see that @pramodk had the same feeling as me:
so my conclusion is that |
Even in Option 2 it's not entirely obvious that it's a large performance penalty, due to move semantics. For example:
Everyone's favourite source suggests that If you're doing something like stripping whitespace from the front, you end up copying the size of the string (minus the leading whitespace). So you don't have to incur a penalty that larger than the cost of the function. Finally, there's Which brings us to the final reason why Option 1 is a bit clunky:
|
One observation, I can't remember seeing any of these functions and I don't immediately see a use for any of them, except ltrim: 1 use |
ah you're making a good point - but we can clean them up nevertheless. |
It's not an argument against cleaning it up. Rather it's an argument that a super ergonomic API maybe isn't as important as we initially thought. Also the cost of changing this if we notice that it's too slow, isn't prohibitive. |
* The prototypes of these functions now follow these 2 principles: 1. the input string is kept intact 2. the transformed text is returned in a new `std::string` instance * Improve the Doxygen documentation Also removed some useless work along the way while updating the calls to these functions. Fixes #1066
* The prototypes of these functions now follow these 2 principles: 1. the input string is kept intact 2. the transformed text is returned in a new `std::string` instance * Improve the Doxygen documentation Also removed some useless work along the way while updating the calls to these functions. Fixes #1066
* The prototypes of these functions now follow these 2 principles: 1. the input string is kept intact 2. the transformed text is returned in a new `std::string` instance * Improve the Doxygen documentation Also removed some useless work along the way while updating the calls to these functions. Fixes #1066 Co-authored-by: Luc Grosheintz <luc.grosheintz-laval@epfl.ch>
Status
Here are some of the utility functions in
src/utils/string_utils.hpp
:We can distinguish 2 categories:
std::string
. Most of these functions also return the reference, probably to use them with a functional style (std::cout << stringutils::trim(my_str)
). Note that the functionremove_character
does not follow that idiom by returningvoid
.std::string
with no side effect. Besides,tolower
should accept a r-value, not an l-value :)Situation
The functions of the first category are a bit misleading, because the fact that they return a
std::string
may suggest that the parameter is not modified, when it actually is.Target
2 solutions:
I prefer to sacrifice the functional style of (2) in the altar of performance by doing in-place edition of the strings with solution (1)
What do you think @ohm314 @pramodk ?
The text was updated successfully, but these errors were encountered: