|
Consider adding a check for certain wasteful calls with std::string that results in unnecessary memory allocations or calls to strlen. For instance: std::string(std::string("abc").c_str()) would be waste and could be simplified as std::string("abc"). While this example is contrived, there are other likely possibilities with implicit constructor calls with StringData. Clang-tidy already has a check called readability-redundant-string-cstr that inspired me.
Potentially useful checks:
1. StringData(std::string("abc").c_str())
- wasteful as it requires a call strlen instead of the StringData(std::string&) constructor
2. StringData(StringData("abc").toString())
- allocates a std::string instead of directly passing a StringData to a StringData.
I am not sure how frequent these or other wasteful patterns with StringData are in the code though. It may or may not be worth considering to adding a clang-tidy check for these.
Reference:
https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-string-cstr.html
Example of a similar check for LLVM's StringRef type.
https://github.com/llvm/llvm-project/blob/3de0bc4c3d0284354b0c0ec8ca1536ee080193e2/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp#L162-L180
|