Use emplace and std::move to optimize [chromium/src : main]

3 views
Skip to first unread message

Daniel Cheng (Gerrit)

unread,
Mar 24, 2026, 1:50:33 PM (9 days ago) Mar 24
to gate kibr, Daniel Cheng, AyeAye, Lei Zhang, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
Attention needed from Lei Zhang and gate kibr

Daniel Cheng voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Lei Zhang
  • gate kibr
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
Gerrit-Change-Number: 7688742
Gerrit-PatchSet: 13
Gerrit-Owner: gate kibr <gkv...@gmail.com>
Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
Gerrit-Attention: gate kibr <gkv...@gmail.com>
Gerrit-Attention: Lei Zhang <the...@chromium.org>
Gerrit-Comment-Date: Tue, 24 Mar 2026 17:50:23 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

gate kibr (Gerrit)

unread,
Mar 26, 2026, 9:32:06 PM (7 days ago) Mar 26
to Daniel Cheng, AyeAye, Lei Zhang, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
Attention needed from Lei Zhang

gate kibr added 1 comment

Patchset-level comments
File-level comment, Patchset 13 (Latest):
gate kibr . resolved

Can submit it CQ for me

Open in Gerrit

Related details

Attention is currently required from:
  • Lei Zhang
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
Gerrit-Change-Number: 7688742
Gerrit-PatchSet: 13
Gerrit-Owner: gate kibr <gkv...@gmail.com>
Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
Gerrit-Attention: Lei Zhang <the...@chromium.org>
Gerrit-Comment-Date: Fri, 27 Mar 2026 01:31:57 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Lei Zhang (Gerrit)

unread,
Mar 26, 2026, 10:08:22 PM (7 days ago) Mar 26
to gate kibr, Daniel Cheng, AyeAye, Lei Zhang, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
Attention needed from gate kibr

Lei Zhang added 3 comments

File base/metrics/field_trial_params.cc
Line 145, Patchset 13 (Latest): auto [it, inserted] = trial_groups.emplace(trial, group);
Lei Zhang . unresolved

I personally prefer:

```
bool inserted = some_container_call().second;
if (!inserted) {
...
}
```

Then there is no unused `it` variable.

Line 156, Patchset 13 (Latest): params[std::move(key)] = std::move(value);
Lei Zhang . unresolved

Just combine with previous line.

File base/scoped_add_feature_flags.cc
Line 88, Patchset 13 (Latest): if (enable) {
enabled_features_.emplace_back(std::move(feature_name));
} else {
disabled_features_.emplace_back(std::move(feature_name));
}
Lei Zhang . unresolved

Can simplify further:

```
auto& container = enable ? enabled_features_ : disabled_features_;
container.emplace_back(...);
```

Open in Gerrit

Related details

Attention is currently required from:
  • gate kibr
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
    Gerrit-Change-Number: 7688742
    Gerrit-PatchSet: 13
    Gerrit-Owner: gate kibr <gkv...@gmail.com>
    Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
    Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
    Gerrit-Attention: gate kibr <gkv...@gmail.com>
    Gerrit-Comment-Date: Fri, 27 Mar 2026 02:08:10 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Will Harris (Gerrit)

    unread,
    Mar 26, 2026, 10:14:25 PM (7 days ago) Mar 26
    to gate kibr, Will Harris, Daniel Cheng, AyeAye, Lei Zhang, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
    Attention needed from gate kibr

    Will Harris added 1 comment

    File base/metrics/field_trial_params.cc
    Line 145, Patchset 13 (Latest): auto [it, inserted] = trial_groups.emplace(trial, group);
    Lei Zhang . unresolved

    I personally prefer:

    ```
    bool inserted = some_container_call().second;
    if (!inserted) {
    ...
    }
    ```

    Then there is no unused `it` variable.

    Will Harris

    driveby - you could use placeholder too

    `auto [_, inserted] = ...`

    e.g. https://source.chromium.org/search?q=%22auto%20%5B_%22&ss=chromium

    Open in Gerrit

    Related details

    Attention is currently required from:
    • gate kibr
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
    Gerrit-Change-Number: 7688742
    Gerrit-PatchSet: 13
    Gerrit-Owner: gate kibr <gkv...@gmail.com>
    Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
    Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
    Gerrit-CC: Will Harris <w...@chromium.org>
    Gerrit-Attention: gate kibr <gkv...@gmail.com>
    Gerrit-Comment-Date: Fri, 27 Mar 2026 02:14:14 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    gate kibr (Gerrit)

    unread,
    Mar 26, 2026, 11:30:42 PM (7 days ago) Mar 26
    to Will Harris, Daniel Cheng, AyeAye, Lei Zhang, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
    Attention needed from Daniel Cheng, Lei Zhang and Will Harris

    gate kibr added 3 comments

    File base/metrics/field_trial_params.cc
    Line 145, Patchset 13: auto [it, inserted] = trial_groups.emplace(trial, group);
    Lei Zhang . resolved

    I personally prefer:

    ```
    bool inserted = some_container_call().second;
    if (!inserted) {
    ...
    }
    ```

    Then there is no unused `it` variable.

    Will Harris

    driveby - you could use placeholder too

    `auto [_, inserted] = ...`

    e.g. https://source.chromium.org/search?q=%22auto%20%5B_%22&ss=chromium

    gate kibr

    Done, Thanks will

    Line 156, Patchset 13: params[std::move(key)] = std::move(value);
    Lei Zhang . resolved

    Just combine with previous line.

    gate kibr

    Done

    File base/scoped_add_feature_flags.cc
    Line 88, Patchset 13: if (enable) {

    enabled_features_.emplace_back(std::move(feature_name));
    } else {
    disabled_features_.emplace_back(std::move(feature_name));
    }
    Lei Zhang . resolved

    Can simplify further:

    ```
    auto& container = enable ? enabled_features_ : disabled_features_;
    container.emplace_back(...);
    ```

    gate kibr

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Daniel Cheng
    • Lei Zhang
    • Will Harris
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
      Gerrit-Change-Number: 7688742
      Gerrit-PatchSet: 15
      Gerrit-Owner: gate kibr <gkv...@gmail.com>
      Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
      Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
      Gerrit-CC: Will Harris <w...@chromium.org>
      Gerrit-Attention: Lei Zhang <the...@chromium.org>
      Gerrit-Attention: Will Harris <w...@chromium.org>
      Gerrit-Attention: Daniel Cheng <dch...@chromium.org>
      Gerrit-Comment-Date: Fri, 27 Mar 2026 03:30:17 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
      Comment-In-Reply-To: Will Harris <w...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Lei Zhang (Gerrit)

      unread,
      Mar 27, 2026, 1:37:59 PM (6 days ago) Mar 27
      to gate kibr, Lei Zhang, Will Harris, Daniel Cheng, AyeAye, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
      Attention needed from Daniel Cheng, Will Harris and gate kibr

      Lei Zhang voted

      Code-Review+1
      Commit-Queue+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Daniel Cheng
      • Will Harris
      • gate kibr
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
      Gerrit-Change-Number: 7688742
      Gerrit-PatchSet: 16
      Gerrit-Owner: gate kibr <gkv...@gmail.com>
      Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
      Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
      Gerrit-CC: Will Harris <w...@chromium.org>
      Gerrit-Attention: gate kibr <gkv...@gmail.com>
      Gerrit-Attention: Will Harris <w...@chromium.org>
      Gerrit-Attention: Daniel Cheng <dch...@chromium.org>
      Gerrit-Comment-Date: Fri, 27 Mar 2026 17:37:43 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Will Harris (Gerrit)

      unread,
      Mar 27, 2026, 7:54:33 PM (6 days ago) Mar 27
      to gate kibr, Will Harris, Chromium LUCI CQ, Lei Zhang, Daniel Cheng, AyeAye, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
      Attention needed from Daniel Cheng and gate kibr

      Will Harris voted and added 1 comment

      Votes added by Will Harris

      Code-Review+1

      1 comment

      Patchset-level comments
      File-level comment, Patchset 16 (Latest):
      Will Harris . resolved

      if lei is okay then I am okay too.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Daniel Cheng
      • gate kibr
      Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
        Gerrit-Change-Number: 7688742
        Gerrit-PatchSet: 16
        Gerrit-Owner: gate kibr <gkv...@gmail.com>
        Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
        Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
        Gerrit-Reviewer: Will Harris <w...@chromium.org>
        Gerrit-Attention: gate kibr <gkv...@gmail.com>
        Gerrit-Attention: Daniel Cheng <dch...@chromium.org>
        Gerrit-Comment-Date: Fri, 27 Mar 2026 23:54:22 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        open
        diffy

        Daniel Cheng (Gerrit)

        unread,
        Mar 28, 2026, 1:26:55 AM (6 days ago) Mar 28
        to gate kibr, Daniel Cheng, Will Harris, Chromium LUCI CQ, Lei Zhang, AyeAye, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
        Attention needed from gate kibr

        Daniel Cheng voted Commit-Queue+2

        Commit-Queue+2
        Open in Gerrit

        Related details

        Attention is currently required from:
        • gate kibr
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
        Gerrit-Change-Number: 7688742
        Gerrit-PatchSet: 16
        Gerrit-Owner: gate kibr <gkv...@gmail.com>
        Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
        Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
        Gerrit-Reviewer: Will Harris <w...@chromium.org>
        Gerrit-Attention: gate kibr <gkv...@gmail.com>
        Gerrit-Comment-Date: Sat, 28 Mar 2026 05:26:43 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        open
        diffy

        Daniel Cheng (Gerrit)

        unread,
        Mar 28, 2026, 1:27:02 AM (6 days ago) Mar 28
        to gate kibr, Daniel Cheng, Will Harris, Chromium LUCI CQ, Lei Zhang, AyeAye, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com
        Attention needed from gate kibr

        Daniel Cheng voted Code-Review+1

        Code-Review+1
        Open in Gerrit

        Related details

        Attention is currently required from:
        • gate kibr
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
        Gerrit-Change-Number: 7688742
        Gerrit-PatchSet: 16
        Gerrit-Owner: gate kibr <gkv...@gmail.com>
        Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
        Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
        Gerrit-Reviewer: Will Harris <w...@chromium.org>
        Gerrit-Attention: gate kibr <gkv...@gmail.com>
        Gerrit-Comment-Date: Sat, 28 Mar 2026 05:26:51 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        open
        diffy

        Chromium LUCI CQ (Gerrit)

        unread,
        Mar 28, 2026, 1:41:28 AM (6 days ago) Mar 28
        to gate kibr, Daniel Cheng, Will Harris, Lei Zhang, AyeAye, tracing...@chromium.org, wfh+...@chromium.org, spang...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com

        Chromium LUCI CQ submitted the change

        Change information

        Commit message:
        Use emplace and std::move to optimize

        - Replace find()+insert() pattern with emplace()
        - Use std::move() + emplace
        - Use iterators when erasing
        Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
        Commit-Queue: Daniel Cheng <dch...@chromium.org>
        Reviewed-by: Lei Zhang <the...@chromium.org>
        Reviewed-by: Will Harris <w...@chromium.org>
        Reviewed-by: Daniel Cheng <dch...@chromium.org>
        Cr-Commit-Position: refs/heads/main@{#1606630}
        Files:
        • M base/metrics/field_trial_params.cc
        • M base/scoped_add_feature_flags.cc
        • M base/supports_user_data.cc
        • M base/trace_event/trace_config.cc
        Change size: S
        Delta: 4 files changed, 9 insertions(+), 15 deletions(-)
        Branch: refs/heads/main
        Submit Requirements:
        • requirement satisfiedCode-Review: +1 by Will Harris, +1 by Daniel Cheng, +1 by Lei Zhang
        Open in Gerrit
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: merged
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: I361b379d1a383bd6126bb90fd069d2dca7d31afb
        Gerrit-Change-Number: 7688742
        Gerrit-PatchSet: 17
        Gerrit-Owner: gate kibr <gkv...@gmail.com>
        Gerrit-Reviewer: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
        open
        diffy
        satisfied_requirement
        Reply all
        Reply to author
        Forward
        0 new messages