Closed dcb314 closed 4 months ago
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
test/
create fine-grained testing targets, so you can e.g. use make check-clang-ast
to only run Clang's AST tests.git clang-format HEAD~1
to format your changes.If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: None (dcb314)
Function signature hasn't changed, so I fail to understand how the commit fixes the problem.
AFAIK, the code still pointlessly copies a vector of string and changing the body of the function doesn't affect the signature.
Suggest use of const reference in the function signature.
Due to the internal move, the vector is now only copied once instead of twice previously. That's what Cppcheck actually complains about in my understanding.
May I refer the right honourable gentleman to the answer I gave earlier ?
To quote:
Suggest use of const reference in the function signature.
Then zero copies, not one or two, will result.
It's unclear to me why there's no copy. Up to the point when the setter is called, the target variable Config.MAttrs
is empty. Means, calling the setter results in a memory allocation. The constant reference would save a move, but how can there be no copy?
but how can there be no copy?
Perhaps I've been slightly less than clear. Either that or perhaps you are new to C++ ?
Suggest change function signature from
void setAttrs(std::vector std::string MAttrs) {
to
void setAttrs(const std::vector std::string & MAttrs) {
That's all that cppcheck was complaining about.
If you don't understand the difference between these two signatures, can I be so bold as to suggest some C++ training ?
No worries, I very well understand what Cppcheck suggests. What I don't get is how that's superior compared to what there's now. Cppcheck, at least, appears to be happy with the "fix". But never mind, seems like I'm not going to find an answer here after reflecting and asking three times.
Can I be so bold as to suggest you some communication training?
What I don't get is how that's superior compared to what there's now.
Then you don't understand a basic feature of C++ parameter passing. More detail on
https://www.learncpp.com/cpp-tutorial/pass-by-const-lvalue-reference/
Can I be so bold as to suggest you some communication training?
Always a wise idea. I've been doing C++ for nearly 40 years now and sometimes forget we were all new once.
Thanks for your persistence.
Static analyser cppcheck says:
llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h:100:42: performance: Function parameter 'MAttrs' should be passed by const reference. [passedByValue]
Source code is
void setAttrs(std::vector MAttrs) { Config.MAttrs = MAttrs; }