Skip to content

Performance tweaks#3468

Open
edding3000 wants to merge 10 commits intoowasp-modsecurity:v3/masterfrom
edding3000:performance_tweaks
Open

Performance tweaks#3468
edding3000 wants to merge 10 commits intoowasp-modsecurity:v3/masterfrom
edding3000: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?

@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

airween commented Nov 20, 2025

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

@airween airween added the 3.x Related to ModSecurity version 3.x label Jan 24, 2026
@airween
Copy link
Member

airween commented Jan 24, 2026

Hi @edding3000,

sorry for the long delay, it seems like this PR is ready to merge. Just one question: could you merge the current v3/master into this one?

@airween
Copy link
Member

airween commented Jan 24, 2026

@edding3000,

also please take a look at the few request changes.

@sonarqubecloud
Copy link

@edding3000
Copy link
Author

@airween I merged v3/master. cppcheck fails now. Can you see the reason?

@airween
Copy link
Member

airween commented Feb 17, 2026

@airween I merged v3/master. cppcheck fails now. Can you see the reason?

Yes:

2026-02-17T18:48:51.1404560Z warning: src/run_time_string.cc,54,style,functionConst,The member function 'modsecurity::RunTimeString::evaluate' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?

I think cppcheck realized that you changed the loop's variable to const, and figured out the function can't change the object (I don't see the relationship what this const triggered this error), so it expects to make the fn to const - but warns us that it might be wrong.

So what you can try now:

  • change the function signature to const: std::string RunTimeString::evaluate(Transaction *t, Rule *r) const {
  • if the build will be failed, rollback that change and add an inline suppression to that line: std::string RunTimeString::evaluate(Transaction *t, Rule *r) { // cppcheck-suppress functionConst
  • in this case, please add this note to the PR's description

Do you have cppcheck on your local dev environment? It's important to use the latest release, and on Linux only Debian SID contains that version. Here you can see how do we use it in Docker.

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

Labels

3.x Related to ModSecurity version 3.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants