Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
edding3000 wants to merge8 commits intoowasp-modsecurity:v3/master
base:v3/master
Choose a base branch
Loading
fromedding3000:performance_tweaks

Conversation

@edding3000
Copy link

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?


lua_newtable(L);
for (auto i : l) {
for (auto* i : l) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
for (auto* i : l) {
for (constauto* i : l) {

Theoriginal 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 withsetvar()).

If we want to keep this restriction, please consider to useconst modifier here.

}

for (auto z : m_ranges) {
for (auto& z : m_ranges) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
for (auto& z : m_ranges) {
for (constauto& z : m_ranges) {

Please seecppcheck'swarning:

warning: src/rules_exceptions.cc,198,style,constVariableReference,Variable 'z' can be declared as reference to const

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sonarcloud also reportsthis.

}
}
for (auto b : from->m_ranges) {
for (auto& b : from->m_ranges) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
for (auto& b : from->m_ranges) {
for (constauto& b : from->m_ranges) {

Please see cppcheck'swarning:

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
for (auto& a : m_rulesMessages) {
for (constauto& a : m_rulesMessages) {

Probably here you could useconst too.

strlen("tags"));
yajl_gen_array_open(g);
for (auto b : a.m_tags) {
for (auto& b : a.m_tags) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
for (auto& b : a.m_tags) {
for (constauto& b : a.m_tags) {

Probably here you could useconst too.

@edding3000
Copy link
Author

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.

@airween
Copy link
Member

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...)

@sonarqubecloud
Copy link

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@airweenairweenairween requested changes

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@edding3000@airween

[8]ページ先頭

©2009-2025 Movatter.jp