Add check performance-faster-string-find.
It replaces single character string literals to character literals in calls to string::find and friends.
Details
Diff Detail
Event Timeline
Awesome! See a few comments inline.
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
51 | Probably out of scope of this patch, but I wonder how many times hasName is still more effective than one matchesName? Maybe we should add a matchesName variant for unqualified names or hasName taking a list of strings? | |
57 | const auto & would be slightly clearer. | |
75 | The message might be confusing in some situations (e.g. macros). I think, it should at least mention what method (and maybe of what class) is in question, e.g. "std::string::find() called with a string literal consisting of a single character; consider using the more effective overload accepting a character". | |
clang-tidy/performance/FasterStringFindCheck.h | ||
15 | Sort includes, please. | |
test/clang-tidy/performance-faster-string-find.cpp | ||
8 | Should we move stubs to a common header(s)? | |
9 | Did you mean const T *? | |
31 | As usual, please add tests with templates and macros ;) | |
32 | Please add tests for std::wstring, std::u16string and std::u32string. At the very least, we should ensure we don't break the code using them. | |
50 | "Some other methods." maybe? |
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
25 | I don't see much value in this, since it's not someone will change frequently (I guess, once per codebase on average). |
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
25 |
Anything that's user-facing should be fault tolerant and sanitized for a better user experience. |
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
25 | I also don't feel strongly about this. Trimming all strings after splitting should be a trivial 2-line addition to this patch. |
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
51 | I have no idea how much more expensive is the regex engine. | |
75 | Used unqualified function name instead. |
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
30 | I think hasName() will assert if given an empty string, so this should probably also guard against a class list like ",basic_string". | |
test/clang-tidy/performance-faster-string-find.cpp | ||
10 |
Yes, please. However, that can be a separate patch that does something more comprehensive. |
More checks in argument parsing.
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
30 | Also changed the separator to be ';' instead of ','. |
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
31 |
That's a great catch! @alexfh -- do you think we should try to get our checkers to be consistent with their choice of list separators? Specifically, I am thinking about D16113. It seems like it would improve the user experience to not have to wonder "do I use comma, or semi colon, for this list?" |
clang-tidy/performance/FasterStringFindCheck.h | ||
---|---|---|
26 | I think you need to add document about StringLikeClasses option here. |
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
31 | We can try to be consistent with the choice of delimiters, but I'm not sure we can use the same delimiter always without introducing more syntax complexities like escaping or the use of quotes (like in CSV). In any case, we should clearly document the format for each option and think how we can issue diagnostics when we suspect incorrect format used in the option value. | |
73 | This has to use the same delimiter. Maybe pull it to a constant to avoid inconsistency? | |
clang-tidy/performance/FasterStringFindCheck.h | ||
26 | Not here, in the .rst file, please. |
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
31 | I think we should strive for consistency with ";" for right now, and agree that documentation/assistance is a reasonable fallback. |
Make the delimiter a constant and fix mismatch between parse/serialize of the option.
LGTM with one tiny nit.
clang-tidy/performance/FasterStringFindCheck.cpp | ||
---|---|---|
45 | Minor nit: missing punctuation for the comment. |
Sort includes, please.