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

Various fixes about [h|c]pp #6672

Merged

Conversation

bencsikandrei
Copy link
Contributor

@bencsikandrei bencsikandrei commented May 2, 2022

Hello!

I'll detail the small changes I've made in the bunch of commits I've made. On all changes, please correct me if I made assumptions that are not valid, I'm trying my best to read and understand (and test) but I'm still in the process of discovering the project.

  1. There were some minor typos inside the comments of about.hpp and I figured they were worth committing.

  2. std::vector::insert can be called with an empty range as it does a check internally (via its loop) so I figured the if was not needed

  3. found a place where a std::map was searched twice via [], doesn't matter much since it's probably called very seldom but it looks a bit better with the .find, I think. Please correct me on this if I'm wrong, but I figured adding the (empty) entry (via []) to the map in case of not found wasn't useful. If it is, then that change is wrong.

  4. AFAIK default constructors are already called so there was no need to call them in the initializer lists

  5. std::pair was used but its official header not included (it's most probably included by vector, or string) but I think it's safer like this

Thanks again for the awesome project and for the time to review my PR!

Have a good one!

EDIT: Please tell me if I'd better squash these, cause I'll do it no probs!

src/about.cpp Outdated
}

return images_general;
if(const auto it = images_campaigns.find(campaign); it == images_campaigns.cend()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel that if(...; it != images_campaign.cend()) would be better - put the handling for there being images in the if block, and the fallback when there aren't images in the else block.

Generally, I find the old version of this function easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback!
I'll rework it to look similar to that one while still avoiding the double operator[]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the change

@Pentarctagon
Copy link
Member

EDIT: Please tell me if I'd better squash these, cause I'll do it no probs!

I'd say squash, given these are fairly small changes all to the same header+source file.

@Pentarctagon
Copy link
Member

AFAIK default constructors are already called so there was no need to call them in the initializer lists

It's something fairly widely done in the codebase though, so unless there's a particular reason to change it, I don't think the initializer lists would need to be removed.

Otherwise it seems fine, barring any additional comment from stevecotton.

@CelticMinstrel
Copy link
Member

Personally, I wouldn't add them but I wouldn't remove them either, unless maybe I was doing a pass of removing unnecessary constructor initializers across the whole codebase. So either way is fine with me really.

@bencsikandrei
Copy link
Contributor Author

Personally, I wouldn't add them but I wouldn't remove them either, unless maybe I was doing a pass of removing unnecessary constructor initializers across the whole codebase. So either way is fine with me really.

I'm on board with consistency, indeed the pattern is used across the project. I like your idea a lot.

Would a clang-tidy pass with https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-default-member-init.html sound good?

I'll make the change so that it still uses initializer lists

* Fix minor typos in about.hpp comments
* Insert can be called with empty range
* Avoid 1 map search in get_background_images
* Default constructors already called for vector, string and tstring
* Add missing include for std::pair
* Reorder if statement for clarity
@Pentarctagon
Copy link
Member

I'd say open a separate PR for it, and then discussion can be done there based on what changes it makes.

@Pentarctagon Pentarctagon merged commit 5cd1527 into wesnoth:master May 10, 2022
@bencsikandrei bencsikandrei deleted the various_fixes_about_h_c_pp branch May 13, 2022 19:37
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.

None yet

4 participants