-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Performance tweaks #3468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3/master
Are you sure you want to change the base?
Performance tweaks #3468
Conversation
|
|
|
||
| lua_newtable(L); | ||
| for (auto i : l) { | ||
| for (auto* i : l) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (auto* i : l) { | |
| for (const auto* i : l) { |
The original code was written about 8 years ago, the author is no longer involved in development.
If I had to guess why they used value copy mechanism, I would say they wanted to avoid any chance to modify the value on Lua stack (except for intentional change with setvar()).
If we want to keep this restriction, please consider to use const modifier here.
| } | ||
|
|
||
| for (auto z : m_ranges) { | ||
| for (auto& z : m_ranges) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (auto& z : m_ranges) { | |
| for (const auto& z : m_ranges) { |
Please see cppcheck's warning:
warning: src/rules_exceptions.cc,198,style,constVariableReference,Variable 'z' can be declared as reference to const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonarcloud also reports this.
| } | ||
| } | ||
| for (auto b : from->m_ranges) { | ||
| for (auto& b : from->m_ranges) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (auto& b : from->m_ranges) { | |
| for (const auto& b : from->m_ranges) { |
Please see cppcheck's warning:
warning: src/rules_exceptions.cc,215,style,constVariableReference,Variable 'b' can be declared as reference to const
| strlen("messages")); | ||
| yajl_gen_array_open(g); | ||
| for (auto a : m_rulesMessages) { | ||
| for (auto& a : m_rulesMessages) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (auto& a : m_rulesMessages) { | |
| for (const auto& a : m_rulesMessages) { |
Probably here you could use const too.
| strlen("tags")); | ||
| yajl_gen_array_open(g); | ||
| for (auto b : a.m_tags) { | ||
| for (auto& b : a.m_tags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (auto& b : a.m_tags) { | |
| for (const auto& b : a.m_tags) { |
Probably here you could use const too.
|
I was not sure if there was any restriction not to use const, thats why i asked. I could extend the PR with more positions for "const auto&" if you like. |
Sure, go! If the tests will be passed, I'll be happy :). Btw you could review the tests too, may be you will find some lack there too (for eg. you're checking the code...) |



what
Range based for loops with references are already used in this project, but in a few places not.
I am not sure why. I changed this code locations and executed unit tests.
Also use '*' for pointers when using auto keyword, makes it more readable.
why
Improve performance a little bit.
questions
"const auto&" could also be used in many places. Is there a reason why it is not used?