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

Enable performance-inefficient-vector-operation #48480

Conversation

jbytheway
Copy link
Contributor

Summary

None

Purpose of change

More static analysis.

This check looks for simple opportunities to use vector::reserve before a loop which pushes a known number of things to a vector. This is a simple performance optimization which can be quite beneficial in hot parts of the code by replacing O(log(n)) allocations by a single allocation (and reducing copying).

Describe the solution

Enable the check and run clang-tidy. All changes were done automatically by clang-tidy FIXITs.

Describe alternatives you've considered

None.

Testing

Unit tests.

Additional context

Probably none of the specific changes in this PR matter for performance, because any places that did matter have probably already had a reserve call added. But by enabling this check we help ensure that new code doesn't miss out on this simple optimization.

@jbytheway jbytheway requested a review from KorGgenT as a code owner April 11, 2021 14:06
@BrettDong BrettDong added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Apr 11, 2021
@jbytheway jbytheway force-pushed the clang-tidy_performance-inefficient-vector-operation branch from 6051d99 to 2697c69 Compare April 13, 2021 12:26
@ZhilkinSerg ZhilkinSerg merged commit 0d244f0 into CleverRaven:0.F-dev Apr 13, 2021
@ZhilkinSerg ZhilkinSerg mentioned this pull request Apr 13, 2021
14 tasks
@jbytheway jbytheway deleted the clang-tidy_performance-inefficient-vector-operation branch April 14, 2021 00:52
ZhilkinSerg pushed a commit that referenced this pull request Apr 20, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request Apr 20, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request Apr 20, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request May 28, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request May 28, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request May 31, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request Jun 21, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
ZhilkinSerg pushed a commit that referenced this pull request Jul 3, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
anothersimulacrum pushed a commit to anothersimulacrum/Cataclysm-DDA that referenced this pull request Jul 3, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
KorGgenT pushed a commit to KorGgenT/Cataclysm-DDA that referenced this pull request Jul 4, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
Maleclypse pushed a commit to Maleclypse/Cataclysm-DDA that referenced this pull request Jul 4, 2021
* Add a collection of `vector::reserve` calls.

All changes done automatically by clang-tidy.

* Enable performance-inefficient-vector-operation
Maleclypse added a commit to Maleclypse/Cataclysm-DDA that referenced this pull request Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants