Skip to content

php_amule_lib/php_syntree: use some const arguments - #190

Merged
gonosztopi merged 2 commits into
amule-project:masterfrom
sc0w:PR_cppcheck_passedByValue
Jun 2, 2020
Merged

php_amule_lib/php_syntree: use some const arguments#190
gonosztopi merged 2 commits into
amule-project:masterfrom
sc0w:PR_cppcheck_passedByValue

Conversation

@sc0w

@sc0w sc0w commented May 27, 2020

Copy link
Copy Markdown
Member

No description provided.

@gonosztopi

Copy link
Copy Markdown
Member

It's okay, but if you started it already, then why didn't you take it all way long? I mean you could also check whether the arrkey parameter for array_get_by_str_key is passed by value or by reference, and change it to a const reference, too.

If the mere reason of existence for a commit is to silence a cppcheck warning, it's likely to be rejected. Also I'd appreciate if you could provide a bit more detailed commit messages.

@sc0w

sc0w commented May 29, 2020

Copy link
Copy Markdown
Member Author

you are wrong, it can't be done the same with arrkey variable into array_get_by_str_key function because the build fails

@gonosztopi

Copy link
Copy Markdown
Member

you are wrong, it can't be done the same with arrkey variable into array_get_by_str_key function because the build fails

How did it fail for you? For me this works.

@sc0w
sc0w force-pushed the PR_cppcheck_passedByValue branch from 777cae7 to 873d5cd Compare May 30, 2020 16:33
@sc0w

sc0w commented May 30, 2020

Copy link
Copy Markdown
Member Author

Sorry, you are right, thanks for testing, I forgot to change .h file

I updated the PR, please review again

@sc0w
sc0w force-pushed the PR_cppcheck_passedByValue branch from 873d5cd to ce08f1c Compare May 30, 2020 16:38
@sc0w sc0w changed the title php_amule_lib: parameter 'arrkey' should be passed by const reference php_amule_lib/php_syntree: use some const arguments May 30, 2020
@gonosztopi

Copy link
Copy Markdown
Member

May I give you a task?

Array keys are immutable, thus I think all function parameters that are array keys could be changed to a const reference. That would mostly affect php_syntree or maybe php_core_lib. Are you up to the challenge? (And please provide some descriptive commit message, that also tells us why it's better to use a const reference instead of passing an object by value.)

@sc0w
sc0w force-pushed the PR_cppcheck_passedByValue branch from ce08f1c to 31757ff Compare June 1, 2020 14:22
sc0w added 2 commits June 1, 2020 18:31
A const reference is a reference that does not allow the variable being referenced to be changed through the reference. Consequently, if we use a const reference as a parameter, we guarantee to the caller that the function will not change the argument.
@sc0w
sc0w force-pushed the PR_cppcheck_passedByValue branch from 31757ff to a5d9609 Compare June 1, 2020 16:32
@sc0w

sc0w commented Jun 1, 2020

Copy link
Copy Markdown
Member Author

@gonosztopi please review again

@gonosztopi gonosztopi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although I thought of something like passing an object by const reference is much faster than passing by value while still ensuring that the original object won't get changed, it's okay from me. :-)

@gonosztopi
gonosztopi merged commit bcb39a8 into amule-project:master Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants