Skip to content
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

Some const correctness, upgrades to c++17, and lint suggestions #3143

Closed
wants to merge 15 commits into from

Conversation

marioortizmanero
Copy link
Contributor

@marioortizmanero marioortizmanero commented Mar 15, 2021

I've been manually reviewing the code for some improvements regarding #3099, #3139 and #297. Here are the main changes:

  • Added explicit to constructors with a single parameter. Reference. All of them suggested by clang-tidy.
  • Some early returns: most make the code considerably easier to read. But they're a bit tricky in reviews so not all are included. Applied manually from rg 'if \(!error\)' and rg 'if \(!result\)'.
  • Added [[nodiscard]] to getters and similar functions. Reference. All of them suggested by clang-tidy.
  • Added const to a good chunk of the codebase. I haven't found a way to do this automatically so not all of them are included yet. I've enforced that all of them are in the T const order, as it was the most commonly used one. Unfortunately, this can't be checked automatically with clang-format for now.
  • Removed unused headers. All of them recommended by the CLion IDE.
  • Removed const T parameters in headers, as they have no effect. Reference. All of them suggested by clang-tidy.

I'm not adding more changes related to early returns because there are so many lines modified already and I wanted to keep the PR smaller. If it's too much I can split it up or something. Sorry about that.

@marioortizmanero marioortizmanero marked this pull request as draft March 15, 2021 01:28
{
std::cerr << boost::str (boost::format ("Starting generation profiling. Difficulty: %1$#x (%2%x from base difficulty %3$#x)\n") % difficulty % nano::to_string (nano::difficulty::to_multiplier (difficulty, network_constants.publish_full.base), 4) % network_constants.publish_full.base);
while (!result)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This while(!result) and the previous if (!result) didn't make much sense because the code guaranteed result would be untouched and thus equal to 0. So I just ignored the if and added a while (true) instead.

@marioortizmanero
Copy link
Contributor Author

marioortizmanero commented Mar 15, 2021

I've also removed the [[nodiscard]] attributes, as #3119 is already working on that (although I added very few of them in comparison).

@@ -1633,17 +1633,17 @@ void nano::wallets::reload ()
}
// Delete non existing wallets from memory
std::vector<nano::wallet_id> deleted_items;
for (auto i : items)
Copy link
Contributor Author

@marioortizmanero marioortizmanero Mar 15, 2021

Choose a reason for hiding this comment

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

I changed the name of i here because it was overshadowing the previously declared i, but perhaps that's not necessary

@marioortizmanero
Copy link
Contributor Author

OK I've reviewed my own PR and the changes seem to be correct. I won't be making any more modifications other than possible suggestions from reviews.

The only hard to check parts of this PR are the early returns, as most others would not compile if invalid, and because the git diff here on GitHub is a bit messed up. Specially entry.cpp was a bit tricky because it was a huge function, so let me know if I missed something there.

@marioortizmanero marioortizmanero marked this pull request as ready for review March 15, 2021 12:35
@marioortizmanero marioortizmanero changed the title [WIP] Some const correctness, upgrades to c++17, and lint suggestions Some const correctness, upgrades to c++17, and lint suggestions Mar 16, 2021
@clemahieu
Copy link
Contributor

Thank you very much for doing this cleanup, the changes look good on brief inspection.

I'll figure out when is a good time to include this as it churns a significant amount of files

@zhyatt zhyatt added this to the V23.0 milestone Apr 27, 2021
@zhyatt zhyatt mentioned this pull request Sep 1, 2021
@zhyatt
Copy link
Collaborator

zhyatt commented Oct 6, 2021

@theohax We are interested in having you look at the easier of these various changes to remove the conflicts on and clean up for inclusion.

@theohax
Copy link
Contributor

theohax commented Oct 21, 2021

Superseded by #3510 . Thanks again @marioortizmanero for your contribution!

@theohax theohax closed this Oct 21, 2021
@marioortizmanero
Copy link
Contributor Author

Glad I could be of help! Thanks for cleaning up the PR and fixing the build as well.

@zhyatt zhyatt removed this from the V23.0 milestone Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants