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

clang-tidy modernize-use-emplace #48661

Merged

Conversation

jbytheway
Copy link
Contributor

Summary

None

Purpose of change

More static analysis.

This this check converts push_back into emplace_back (and similarly for similar functions) whenever the argument to push_back is either a constructor call for the type in question of an expression of a type implicitly convertible to the type in question.

This should eliminate one move-construction of the inserted object for each call.

Describe the solution

Enable modernize-use-emplace.

Run clang-tidy.

All changes here were automatically performed by clang-tidy.

Describe alternatives you've considered

There is a readability cost to this check, in that the type being constructed is obscured. If we thought that too costly we might want to disable this check. But in most cases it's fairly obvious, so I think this check is a net win.

Testing

Unit tests.

Additional context

@actual-nh
Copy link
Contributor

How about putting the type being constructed into a comment?

@actual-nh actual-nh added Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Performance Performance boosting code (CPU, memory, etc.) Code: Tests Measurement, self-control, statistics, balancing. labels Apr 26, 2021
@jbytheway
Copy link
Contributor Author

How about putting the type being constructed into a comment?

Yeah, the same idea crossed my mind. Could maybe write another clang-tidy check to implement that, but not in this PR.

src/activity_handlers.cpp Show resolved Hide resolved
src/activity_handlers.cpp Show resolved Hide resolved
src/bionics.cpp Show resolved Hide resolved
src/construction.cpp Show resolved Hide resolved
src/dialogue_win.cpp Show resolved Hide resolved
src/handle_liquid.cpp Show resolved Hide resolved
@jbytheway jbytheway force-pushed the clang-tidy_modernize-use-emplace branch from 93a9177 to ecb4a3a Compare April 28, 2021 00:24
jbytheway added 2 commits May 5, 2021 20:44
This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.
@jbytheway jbytheway force-pushed the clang-tidy_modernize-use-emplace branch from ecb4a3a to 800e75f Compare May 6, 2021 00:45
@ZhilkinSerg ZhilkinSerg merged commit 552d7fa into CleverRaven:0.F-dev May 14, 2021
@ZhilkinSerg ZhilkinSerg mentioned this pull request May 14, 2021
14 tasks
@jbytheway jbytheway deleted the clang-tidy_modernize-use-emplace branch May 15, 2021 09:44
ZhilkinSerg pushed a commit that referenced this pull request May 28, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
ZhilkinSerg pushed a commit that referenced this pull request May 28, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
ZhilkinSerg pushed a commit that referenced this pull request May 31, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
ZhilkinSerg pushed a commit that referenced this pull request Jun 21, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
ZhilkinSerg pushed a commit that referenced this pull request Jul 3, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
anothersimulacrum pushed a commit to anothersimulacrum/Cataclysm-DDA that referenced this pull request Jul 3, 2021
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Performance Performance boosting code (CPU, memory, etc.) Code: Tests Measurement, self-control, statistics, balancing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants