add a performance checker for const assignment - #104
Conversation
|
you also forgot to use astyle. |
In case that he needs a Function instance instead of a token, the new function is useful. However, some kind of funcId system similar to varIds might be a better solution (could handle overloads, namespaces, ...). The problem is just that we don't have it so far. |
|
PKEuS: yes true |
|
And please squash those commits to one commit. You don't need to commit..revert..fix.. Just overwrite/squash the commit with new commit and force push to remote. |
|
Moved checker/test cases into checkother/testother, reverted modifications of cppcheck.sln and testrunner.vcproj. |
|
I found out why I run astyle failed the first time, I just run runastyle.bat in the root folder and did not check out the result before commitment. It's my fault:( |
|
No, external executables don't belong to Cppcheck repository. But the batch file should check if the astyle executable can be found from the path. I'm now on linux so can't do myself add the check in next days. But Stackoverflow has hints/suggestions how to do it: |
|
The error message "Prefer reference than assignment for const variable" is a bit weird. To me it would sound better if "than" is replaced with "in". But it sounds like the assignment should be changed somehow and not the variable, doesn't it? Perhaps: "variable 'a' can be reference to avoid data copy in assignment" or "changing 'a' to a reference avoids data copy". These are just ideas. |
|
Actually I am not so clear whether assignment or variable be changed to reference? |
|
Actually, back to basics.. Do you have any reference for your claim that your suggested code is more efficient? Is it just in some cases, or always etc? Is the performance difference measurable? In real-world code, not just in some micro-benchmarks? |
|
As long as the message is only shown on user defined types, there is obviously a performance gain. It avoids copying data. (Just the same as parameters that are passed by value and not by reference). You usually don't see this message very often, so its nearly impossible to find a real world example. |
|
Suggestions for a message: |
|
@kimmov |
|
@PKEuS If any suggestions, pls feel free to let me know. |
|
Both ideas sound much better than the current message. But the word "Maybe" in the second one is unnecessary. It is redundant. |
|
Changed the error message and the name of functions added. |
|
That looks acceptable now as far as I see. If nobody complains I'll merge it tomorrow. |
|
I took the liberty and edited your commit and pushed it. I pushed it with: Thank you for your work! I hope you'll provide more checks. |
add a performance checker for situation like "const A a = getA()" and getA() returns const A & or A &