[cfe-dev] Reduction of temporaries

Csaba Raduly via cfe-dev cfe-dev at lists.llvm.org
Fri Apr 12 01:55:50 PDT 2019


Hi all,

Recently, one of my colleagues made the following change in our code:

- h += q.substr(0, q_max);
+ h.append  (q, 0, q_max);

This eliminates the temporary std::string returned by substr.

std::string has a few operations (insert/append/replace) that accept a
substring of of the input. Is this something that would be worth
finding automatically? (e.g. a clang-tidy check)

Csaba
-- 
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformat way
to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)


More information about the cfe-dev mailing list