|
|
Chromium Code Reviews
DescriptionUse movable types for CallStackProfile(s) to remove copying of data.
BUG=658883
TBR=jschuh (for security of unittest)
Committed: https://crrev.com/c3c851d8622ae32dfb293181be904788b28d2f0d
Cr-Commit-Position: refs/heads/master@{#427799}
Patch Set 1 #Patch Set 2 : fix tests and build problems #
Total comments: 12
Patch Set 3 : addressed review comments by wittman #
Total comments: 10
Patch Set 4 : address review comments by asvitkine #Patch Set 5 : added some comments about std::move #Messages
Total messages: 80 (64 generated)
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: ios-device on master.tryserver.chromium.mac (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.mac/builders/ios-device/builds...)
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_cronet on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/android_cron...)
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: ios-device on master.tryserver.chromium.mac (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.mac/builders/ios-device/builds...)
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_cronet on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/android_cron...)
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Patchset #4 (id:60001) has been deleted
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Patchset #3 (id:40001) has been deleted
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_compile_dbg on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/android_comp...)
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Patchset #4 (id:100001) has been deleted
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: linux_chromium_chromeos_rel_ng on master.tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_...)
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: linux_chromium_chromeos_rel_ng on master.tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_...)
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Patchset #5 (id:140001) has been deleted
Patchset #2 (id:20001) has been deleted
Patchset #2 (id:80001) has been deleted
Patchset #2 (id:120001) has been deleted
bcwhite@chromium.org changed reviewers: + wittman@chromium.org
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... File base/profiler/stack_sampling_profiler.cc (right): https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler.cc:113: const CallStackProfile& other) = default; nit: function order (this should be last) https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... File base/profiler/stack_sampling_profiler.h (right): https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler.h:133: // Copying is possible but expensive so disallow it; use std::move instead. nit: ... disallow it _from outside the class_ ... https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler.h:134: CallStackProfile(const CallStackProfile& other); should we have DISALLOW_ASSIGN here? https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... File base/profiler/stack_sampling_profiler_unittest.cc (right): https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler_unittest.cc:313: *profiles = std::move(pending_profiles); IWYU: <utility> ... and throughout this CL https://codereview.chromium.org/2438073002/diff/160001/components/metrics/chi... File components/metrics/child_call_stack_profile_collector.cc (right): https://codereview.chromium.org/2438073002/diff/160001/components/metrics/chi... components/metrics/child_call_stack_profile_collector.cc:82: base::Passed(std::move(profiles)))); IWYU: "base/bind_helpers.h" https://codereview.chromium.org/2438073002/diff/160001/components/metrics/chi... File components/metrics/child_call_stack_profile_collector_unittest.cc (right): https://codereview.chromium.org/2438073002/diff/160001/components/metrics/chi... components/metrics/child_call_stack_profile_collector_unittest.cc:56: void CollectProfiles( This function can be removed.
Thanks for addressing, this btw!
https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... File base/profiler/stack_sampling_profiler.cc (right): https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler.cc:113: const CallStackProfile& other) = default; On 2016/10/21 18:05:29, Mike Wittman wrote: > nit: function order (this should be last) Done. https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... File base/profiler/stack_sampling_profiler.h (right): https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler.h:133: // Copying is possible but expensive so disallow it; use std::move instead. On 2016/10/21 18:05:29, Mike Wittman wrote: > nit: ... disallow it _from outside the class_ ... Done. https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler.h:134: CallStackProfile(const CallStackProfile& other); On 2016/10/21 18:05:29, Mike Wittman wrote: > should we have DISALLOW_ASSIGN here? Done, though I don't think it's necessary because I don't believe the method will get generated when there is a "move" version that is defined explicitly. https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... File base/profiler/stack_sampling_profiler_unittest.cc (right): https://codereview.chromium.org/2438073002/diff/160001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler_unittest.cc:313: *profiles = std::move(pending_profiles); On 2016/10/21 18:05:29, Mike Wittman wrote: > IWYU: <utility> > > ... and throughout this CL Done. https://codereview.chromium.org/2438073002/diff/160001/components/metrics/chi... File components/metrics/child_call_stack_profile_collector.cc (right): https://codereview.chromium.org/2438073002/diff/160001/components/metrics/chi... components/metrics/child_call_stack_profile_collector.cc:82: base::Passed(std::move(profiles)))); On 2016/10/21 18:05:29, Mike Wittman wrote: > IWYU: "base/bind_helpers.h" Done. https://codereview.chromium.org/2438073002/diff/160001/components/metrics/chi... File components/metrics/child_call_stack_profile_collector_unittest.cc (right): https://codereview.chromium.org/2438073002/diff/160001/components/metrics/chi... components/metrics/child_call_stack_profile_collector_unittest.cc:56: void CollectProfiles( On 2016/10/21 18:05:29, Mike Wittman wrote: > This function can be removed. Done.
lgtm
bcwhite@chromium.org changed reviewers: + asvitkine@chromium.org
asvitkine@chromium.org: Please review changes in
bcwhite@chromium.org changed reviewers: + jschuh@chromium.org
+jschuh, for some reason this unittest needs a security-owner review: components/metrics/public/cpp/call_stack_profile_struct_traits_unittest.cc
Please create a crbug for this and associate it via BUG= since changes are not trivial things like a comment change. https://codereview.chromium.org/2438073002/diff/180001/base/profiler/stack_sa... File base/profiler/stack_sampling_profiler.h (right): https://codereview.chromium.org/2438073002/diff/180001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler.h:136: DISALLOW_ASSIGN(CallStackProfile); Nit: Add an empty line above this. https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... File components/metrics/call_stack_profile_metrics_provider.cc (right): https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... components/metrics/call_stack_profile_metrics_provider.cc:61: DISALLOW_COPY_AND_ASSIGN(ProfilesState); Indent seems wrong. Run git cl format? https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... File components/metrics/call_stack_profile_metrics_provider.h (right): https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... components/metrics/call_stack_profile_metrics_provider.h:38: base::StackSamplingProfiler::CallStackProfiles profiles); Passing by non-const ref that results in a copy is usually not done in Chromium - so this code and similarly for Collect() in the other file ends up looking like a mistake. a) What's the reason for doing it this way? Can the copy be done inside the function explicitly instead rather than implicitly through the function call? b) Otherwise, if we do want to keep the copy as part of the function call, we should document that it's done so intentionally.
Description was changed from ========== Use movable types for CallStackProfile(s) to remove copying of data. BUG= ========== to ========== Use movable types for CallStackProfile(s) to remove copying of data. BUG=658883 ==========
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
https://codereview.chromium.org/2438073002/diff/180001/base/profiler/stack_sa... File base/profiler/stack_sampling_profiler.h (right): https://codereview.chromium.org/2438073002/diff/180001/base/profiler/stack_sa... base/profiler/stack_sampling_profiler.h:136: DISALLOW_ASSIGN(CallStackProfile); On 2016/10/24 15:26:21, Alexei Svitkine (slow) wrote: > Nit: Add an empty line above this. Done. https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... File components/metrics/call_stack_profile_metrics_provider.cc (right): https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... components/metrics/call_stack_profile_metrics_provider.cc:61: DISALLOW_COPY_AND_ASSIGN(ProfilesState); On 2016/10/24 15:26:22, Alexei Svitkine (slow) wrote: > Indent seems wrong. Run git cl format? Done. https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... File components/metrics/call_stack_profile_metrics_provider.h (right): https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... components/metrics/call_stack_profile_metrics_provider.h:38: base::StackSamplingProfiler::CallStackProfiles profiles); > Passing by non-const ref that results in a copy is usually not done in Chromium > - so this code and similarly for Collect() in the other file ends up looking > like a mistake. CallStackProfiles doesn't allow copy so only std::move is allowed when passing the parameter. The CompletedCallback function type, which is what this is, (stack_sampling_profiler.h:166) documents that these are move-only parameters. The alternative is to use type&& for the parameter but that's against the style guide except for (1) move ctor/assign or (2) perfect forwarding. You could argue that this is a case of #2 but Mojo does its "move-only" parameters in this way (i.e. no &&) so I've elected to follow that style in order to have consistency.
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_clang_dbg_recipe on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/android_clan...)
https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... File components/metrics/call_stack_profile_metrics_provider.h (right): https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... components/metrics/call_stack_profile_metrics_provider.h:38: base::StackSamplingProfiler::CallStackProfiles profiles); On 2016/10/24 21:30:30, bcwhite wrote: > > Passing by non-const ref that results in a copy is usually not done in > Chromium > > - so this code and similarly for Collect() in the other file ends up looking > > like a mistake. > > CallStackProfiles doesn't allow copy so only std::move is allowed when passing > the parameter. The CompletedCallback function type, which is what this is, > (stack_sampling_profiler.h:166) documents that these are move-only parameters. > > The alternative is to use type&& for the parameter but that's against the style > guide except for (1) move ctor/assign or (2) perfect forwarding. > > You could argue that this is a case of #2 but Mojo does its "move-only" > parameters in this way (i.e. no &&) so I've elected to follow that style in > order to have consistency. Sorry, I don't think I'm following. But maybe I don't understand something in C++. How can CallStackProfiles which is a std::vector<CallStackProfile> be move only? Doesn't vector support copy - what's preventing it to be moved? Even then, if it was move only, I don't understand how that would work when you're passing the type by value. As far as I understand, moving requires modifying the original value - but how can a function call modify the original value (when it's not passed by either pointer or non-const ref)? For example, in this code: base::StackSamplingProfiler::CallStackProfiles profiles; profiles.push_back(...); ReceiveCompletedProfiles(params, start_timestamp, profiles); I don't understand how the profiles param can be move only. A move, if I understand correctly, would transfer the contents of profiles into the param - but the above code as written shouldn't modify |profiles| local var in any way - or am I wrong? Or did you mean the caller has to only call the function with std::move(profiles) for the param? If so, that's not what I think of - when reading "move only" - since if the caller doesn't do that, it still would end up copying - and so if that's the intention it should be clearly documented. But perhaps I'm missing something?
https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... File components/metrics/call_stack_profile_metrics_provider.h (right): https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... components/metrics/call_stack_profile_metrics_provider.h:38: base::StackSamplingProfiler::CallStackProfiles profiles); On 2016/10/25 14:34:04, Alexei Svitkine (slow) wrote: > On 2016/10/24 21:30:30, bcwhite wrote: > > > Passing by non-const ref that results in a copy is usually not done in > > Chromium > > > - so this code and similarly for Collect() in the other file ends up > looking > > > like a mistake. > > > > CallStackProfiles doesn't allow copy so only std::move is allowed when passing > > the parameter. The CompletedCallback function type, which is what this is, > > (stack_sampling_profiler.h:166) documents that these are move-only parameters. > > > > The alternative is to use type&& for the parameter but that's against the > style > > guide except for (1) move ctor/assign or (2) perfect forwarding. > > > > You could argue that this is a case of #2 but Mojo does its "move-only" > > parameters in this way (i.e. no &&) so I've elected to follow that style in > > order to have consistency. > > Sorry, I don't think I'm following. But maybe I don't understand something in > C++. > > How can CallStackProfiles which is a std::vector<CallStackProfile> be move only? > Doesn't vector support copy - what's preventing it to be moved? std::vector supports both copy and move construction. If the latter, it just moves some pointers around and steals the data from its parameter. > Even then, if it was move only, I don't understand how that would work when > you're passing the type by value. As far as I understand, moving requires > modifying the original value - but how can a function call modify the original > value (when it's not passed by either pointer or non-const ref)? All true. If it was const, it couldn't be modified at all. Passed by value, the original can't be modified. That means that when calling this, the caller has to explicitly specify std::move(var) in the parameter list. That moves the contents into the parameter which is then moved into its final destination. This, incidentally, is why doing an rvalue-reference (i.e. type&&) would be preferred since it just as lightweight as a regular reference... but is against the style guide and would conflict with the code generated by mojo. > For example, in this code: > > base::StackSamplingProfiler::CallStackProfiles profiles; > profiles.push_back(...); > ReceiveCompletedProfiles(params, start_timestamp, profiles); > > I don't understand how the profiles param can be move only. A move, if I > understand correctly, would transfer the contents of profiles into the param - > but the above code as written shouldn't modify |profiles| local var in any way - > or am I wrong? You're correct. It has to be ReceiveCompletedProfiles(params, start_timestamp, std::move(profiles)); > Or did you mean the caller has to only call the function with > std::move(profiles) for the param? If so, that's not what I think of - when > reading "move only" - since if the caller doesn't do that, it still would end up > copying - and so if that's the intention it should be clearly documented. It's always the way it has to be done. There's no implicit moves allowed where there is any possibility that the variable could be referenced again further down -- that basically means that if it has a name (rather than the result of an expression), then std::move() is required to pass to a move-only (i.e. has move constructor but no copy constructor) parameter. std::unique_ptr is the best example of this. You can never pass it as a parameter without an explicit std::move.
LGTM % comment https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... File components/metrics/call_stack_profile_metrics_provider.h (right): https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... components/metrics/call_stack_profile_metrics_provider.h:38: base::StackSamplingProfiler::CallStackProfiles profiles); On 2016/10/25 15:01:04, bcwhite wrote: > On 2016/10/25 14:34:04, Alexei Svitkine (slow) wrote: > > On 2016/10/24 21:30:30, bcwhite wrote: > > > > Passing by non-const ref that results in a copy is usually not done in > > > Chromium > > > > - so this code and similarly for Collect() in the other file ends up > > looking > > > > like a mistake. > > > > > > CallStackProfiles doesn't allow copy so only std::move is allowed when > passing > > > the parameter. The CompletedCallback function type, which is what this is, > > > (stack_sampling_profiler.h:166) documents that these are move-only > parameters. > > > > > > The alternative is to use type&& for the parameter but that's against the > > style > > > guide except for (1) move ctor/assign or (2) perfect forwarding. > > > > > > You could argue that this is a case of #2 but Mojo does its "move-only" > > > parameters in this way (i.e. no &&) so I've elected to follow that style in > > > order to have consistency. > > > > Sorry, I don't think I'm following. But maybe I don't understand something in > > C++. > > > > How can CallStackProfiles which is a std::vector<CallStackProfile> be move > only? > > Doesn't vector support copy - what's preventing it to be moved? > > std::vector supports both copy and move construction. If the latter, it just > moves some pointers around and steals the data from its parameter. > > > > Even then, if it was move only, I don't understand how that would work when > > you're passing the type by value. As far as I understand, moving requires > > modifying the original value - but how can a function call modify the original > > value (when it's not passed by either pointer or non-const ref)? > > All true. If it was const, it couldn't be modified at all. Passed by value, > the original can't be modified. > > That means that when calling this, the caller has to explicitly specify > std::move(var) in the parameter list. That moves the contents into the > parameter which is then moved into its final destination. > > This, incidentally, is why doing an rvalue-reference (i.e. type&&) would be > preferred since it just as lightweight as a regular reference... but is against > the style guide and would conflict with the code generated by mojo. > > > > For example, in this code: > > > > base::StackSamplingProfiler::CallStackProfiles profiles; > > profiles.push_back(...); > > ReceiveCompletedProfiles(params, start_timestamp, profiles); > > > > I don't understand how the profiles param can be move only. A move, if I > > understand correctly, would transfer the contents of profiles into the param - > > but the above code as written shouldn't modify |profiles| local var in any way > - > > or am I wrong? > > You're correct. It has to be > > ReceiveCompletedProfiles(params, start_timestamp, std::move(profiles)); > > > > Or did you mean the caller has to only call the function with > > std::move(profiles) for the param? If so, that's not what I think of - when > > reading "move only" - since if the caller doesn't do that, it still would end > up > > copying - and so if that's the intention it should be clearly documented. > > It's always the way it has to be done. There's no implicit moves allowed where > there is any possibility that the variable could be referenced again further > down -- that basically means that if it has a name (rather than the result of an > expression), then std::move() is required to pass to a move-only (i.e. has move > constructor but no copy constructor) parameter. > > std::unique_ptr is the best example of this. You can never pass it as a > parameter without an explicit std::move. OK, so given the above, please add a comment to each function where you have such a parameter that mentions that it's passed by value so that the caller can use std::move() to avoid copies. This way, having such a comment makes it explicit that it's intentional that it's being passed by value (and not a mistake of someone forgetting to put const&).
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Patchset #5 (id:220001) has been deleted
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... File components/metrics/call_stack_profile_metrics_provider.h (right): https://codereview.chromium.org/2438073002/diff/180001/components/metrics/cal... components/metrics/call_stack_profile_metrics_provider.h:38: base::StackSamplingProfiler::CallStackProfiles profiles); On 2016/10/25 15:21:18, Alexei Svitkine (slow) wrote: > On 2016/10/25 15:01:04, bcwhite wrote: > > On 2016/10/25 14:34:04, Alexei Svitkine (slow) wrote: > > > On 2016/10/24 21:30:30, bcwhite wrote: > > > > > Passing by non-const ref that results in a copy is usually not done in > > > > Chromium > > > > > - so this code and similarly for Collect() in the other file ends up > > > looking > > > > > like a mistake. > > > > > > > > CallStackProfiles doesn't allow copy so only std::move is allowed when > > passing > > > > the parameter. The CompletedCallback function type, which is what this > is, > > > > (stack_sampling_profiler.h:166) documents that these are move-only > > parameters. > > > > > > > > The alternative is to use type&& for the parameter but that's against the > > > style > > > > guide except for (1) move ctor/assign or (2) perfect forwarding. > > > > > > > > You could argue that this is a case of #2 but Mojo does its "move-only" > > > > parameters in this way (i.e. no &&) so I've elected to follow that style > in > > > > order to have consistency. > > > > > > Sorry, I don't think I'm following. But maybe I don't understand something > in > > > C++. > > > > > > How can CallStackProfiles which is a std::vector<CallStackProfile> be move > > only? > > > Doesn't vector support copy - what's preventing it to be moved? > > > > std::vector supports both copy and move construction. If the latter, it just > > moves some pointers around and steals the data from its parameter. > > > > > > > Even then, if it was move only, I don't understand how that would work when > > > you're passing the type by value. As far as I understand, moving requires > > > modifying the original value - but how can a function call modify the > original > > > value (when it's not passed by either pointer or non-const ref)? > > > > All true. If it was const, it couldn't be modified at all. Passed by value, > > the original can't be modified. > > > > That means that when calling this, the caller has to explicitly specify > > std::move(var) in the parameter list. That moves the contents into the > > parameter which is then moved into its final destination. > > > > This, incidentally, is why doing an rvalue-reference (i.e. type&&) would be > > preferred since it just as lightweight as a regular reference... but is > against > > the style guide and would conflict with the code generated by mojo. > > > > > > > For example, in this code: > > > > > > base::StackSamplingProfiler::CallStackProfiles profiles; > > > profiles.push_back(...); > > > ReceiveCompletedProfiles(params, start_timestamp, profiles); > > > > > > I don't understand how the profiles param can be move only. A move, if I > > > understand correctly, would transfer the contents of profiles into the param > - > > > but the above code as written shouldn't modify |profiles| local var in any > way > > - > > > or am I wrong? > > > > You're correct. It has to be > > > > ReceiveCompletedProfiles(params, start_timestamp, std::move(profiles)); > > > > > > > Or did you mean the caller has to only call the function with > > > std::move(profiles) for the param? If so, that's not what I think of - when > > > reading "move only" - since if the caller doesn't do that, it still would > end > > up > > > copying - and so if that's the intention it should be clearly documented. > > > > It's always the way it has to be done. There's no implicit moves allowed > where > > there is any possibility that the variable could be referenced again further > > down -- that basically means that if it has a name (rather than the result of > an > > expression), then std::move() is required to pass to a move-only (i.e. has > move > > constructor but no copy constructor) parameter. > > > > std::unique_ptr is the best example of this. You can never pass it as a > > parameter without an explicit std::move. > > OK, so given the above, please add a comment to each function where you have > such a parameter that mentions that it's passed by value so that the caller can > use std::move() to avoid copies. > > This way, having such a comment makes it explicit that it's intentional that > it's being passed by value (and not a mistake of someone forgetting to put > const&). Done.
The CQ bit was checked by bcwhite@chromium.org to run a CQ dry run
Patchset #5 (id:240001) has been deleted
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
Description was changed from ========== Use movable types for CallStackProfile(s) to remove copying of data. BUG=658883 ========== to ========== Use movable types for CallStackProfile(s) to remove copying of data. BUG=658883 TBR=jschuh (for security of unittest) ==========
The CQ bit was checked by bcwhite@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from wittman@chromium.org, asvitkine@chromium.org Link to the patchset: https://codereview.chromium.org/2438073002/#ps260001 (title: "added some comments about std::move")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Message was sent while issue was closed.
Description was changed from ========== Use movable types for CallStackProfile(s) to remove copying of data. BUG=658883 TBR=jschuh (for security of unittest) ========== to ========== Use movable types for CallStackProfile(s) to remove copying of data. BUG=658883 TBR=jschuh (for security of unittest) ==========
Message was sent while issue was closed.
Committed patchset #5 (id:260001)
Message was sent while issue was closed.
Description was changed from ========== Use movable types for CallStackProfile(s) to remove copying of data. BUG=658883 TBR=jschuh (for security of unittest) ========== to ========== Use movable types for CallStackProfile(s) to remove copying of data. BUG=658883 TBR=jschuh (for security of unittest) Committed: https://crrev.com/c3c851d8622ae32dfb293181be904788b28d2f0d Cr-Commit-Position: refs/heads/master@{#427799} ==========
Message was sent while issue was closed.
Patchset 5 (id:??) landed as https://crrev.com/c3c851d8622ae32dfb293181be904788b28d2f0d Cr-Commit-Position: refs/heads/master@{#427799} |
