这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Use const refs in for loops where reasonable #17484

Merged
merged 1 commit into from
Apr 3, 2020

Conversation

cbracken
Copy link
Member

@cbracken cbracken commented Apr 2, 2020

This patch optimizes C++11 range-based for loops where the variable is
copied in each iteration but it would suffice to obtain it by const
reference. This is only applied to loop variables of types that are
expensive to copy which means they are not trivially copyable or have a
non-trivial copy constructor or destructor.

To ensure that it is safe to replace the copy with a const reference
only the following cases are modified:

  • The loop variable is const qualified.
  • The loop variable is not const, but only const methods or operators
    are invoked on it, or it is used as const reference or value argument
    in constructors or function calls.

This is an application of the internal performance-for-range-copy
clang-tidy analysis.

Copy link
Contributor

@GaryQian GaryQian left a comment

Choose a reason for hiding this comment

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

LGTM!

This patch optimizes C++11 range-based for loops where the variable is
copied in each iteration but it would suffice to obtain it by const
reference. This is only applied to loop variables of types that are
expensive to copy which means they are not trivially copyable or have a
non-trivial copy constructor or destructor.

To ensure that it is safe to replace the copy with a const reference
only the following cases are modified:
  * The loop variable is const-qualified.
  * The loop variable is not const, but only const methods or operators
    are invoked on it, or it is used as const reference or value argument
    in constructors or function calls.

This is an application of the internal performance-for-range-copy
clang-tidy analysis.
@cbracken cbracken merged commit e55b447 into flutter:master Apr 3, 2020
@cbracken cbracken deleted the const-ref-for branch April 3, 2020 18:44
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 3, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 3, 2020
cbracken pushed a commit to flutter/flutter that referenced this pull request Apr 3, 2020
* e55b447 Use const refs in for loops where reasonable (flutter/engine#17484)

* e2b8655 Roll src/third_party/skia 8efbbbc0d1d4..e70e0c055f56 (1 commits) (flutter/engine#17496)

* a9c6222 Roll fuchsia/sdk/core/mac-amd64 from 6V5BR... to tKvUB... (flutter/engine#17497)

* fa09075 Roll fuchsia/sdk/core/linux-amd64 from -jFTb... to TWx2R... (flutter/engine#17498)

* 983d1e1 Fix include paths of fml/time headers in the shell and rasterizer (flutter/engine#17502)

* 09bc1fc Small updates to objcdocs (flutter/engine#17151)
goderbauer pushed a commit to goderbauer/engine that referenced this pull request Apr 16, 2020
This patch optimizes C++11 range-based for loops where the variable is
copied in each iteration but it would suffice to obtain it by const
reference. This is only applied to loop variables of types that are
expensive to copy which means they are not trivially copyable or have a
non-trivial copy constructor or destructor.

To ensure that it is safe to replace the copy with a const reference
only the following cases are modified:
  * The loop variable is const-qualified.
  * The loop variable is not const, but only const methods or operators
    are invoked on it, or it is used as const reference or value argument
    in constructors or function calls.

This is an application of the internal performance-for-range-copy
clang-tidy analysis.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants