Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Unified Diff: components/metrics/child_call_stack_profile_collector.cc

Issue 2438073002: Use movable types for CallStackProfile(s) to remove copying of data. (Closed)
Patch Set: added some comments about std::move Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/metrics/child_call_stack_profile_collector.cc
diff --git a/components/metrics/child_call_stack_profile_collector.cc b/components/metrics/child_call_stack_profile_collector.cc
index 9c62af855688f2d8cae577b1713e8a666bd73f19..ba02cadb1a2ab7bb71eb658101a937dd31f2152a 100644
--- a/components/metrics/child_call_stack_profile_collector.cc
+++ b/components/metrics/child_call_stack_profile_collector.cc
@@ -4,7 +4,10 @@
#include "components/metrics/child_call_stack_profile_collector.h"
+#include <utility>
+
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -13,17 +16,24 @@
namespace metrics {
ChildCallStackProfileCollector::ProfilesState::ProfilesState() = default;
-ChildCallStackProfileCollector::ProfilesState::ProfilesState(
- const ProfilesState&) = default;
+ChildCallStackProfileCollector::ProfilesState::ProfilesState(ProfilesState&&) =
+ default;
ChildCallStackProfileCollector::ProfilesState::ProfilesState(
const CallStackProfileParams& params,
base::TimeTicks start_timestamp,
- const base::StackSamplingProfiler::CallStackProfiles& profiles)
- : params(params), start_timestamp(start_timestamp), profiles(profiles) {}
+ base::StackSamplingProfiler::CallStackProfiles profiles)
+ : params(params),
+ start_timestamp(start_timestamp),
+ profiles(std::move(profiles)) {}
ChildCallStackProfileCollector::ProfilesState::~ProfilesState() = default;
+// Some versions of GCC need this for push_back to work with std::move.
+ChildCallStackProfileCollector::ProfilesState&
+ChildCallStackProfileCollector::ProfilesState::operator=(ProfilesState&&) =
+ default;
+
ChildCallStackProfileCollector::ChildCallStackProfileCollector() {}
ChildCallStackProfileCollector::~ChildCallStackProfileCollector() {}
@@ -47,9 +57,9 @@ void ChildCallStackProfileCollector::SetParentProfileCollector(
task_runner_ = base::ThreadTaskRunnerHandle::Get();
parent_collector_ = std::move(parent_collector);
if (parent_collector_) {
- for (const ProfilesState& state : profiles_) {
+ for (ProfilesState& state : profiles_) {
parent_collector_->Collect(state.params, state.start_timestamp,
- state.profiles);
+ std::move(state.profiles));
}
}
profiles_.clear();
@@ -58,7 +68,7 @@ void ChildCallStackProfileCollector::SetParentProfileCollector(
void ChildCallStackProfileCollector::Collect(
const CallStackProfileParams& params,
base::TimeTicks start_timestamp,
- const std::vector<CallStackProfile>& profiles) {
+ std::vector<CallStackProfile> profiles) {
base::AutoLock alock(lock_);
if (task_runner_ &&
// The profiler thread does not have a task runner. Attempting to
@@ -72,14 +82,15 @@ void ChildCallStackProfileCollector::Collect(
base::Unretained(this),
params,
start_timestamp,
- profiles));
+ base::Passed(std::move(profiles))));
return;
}
if (parent_collector_) {
- parent_collector_->Collect(params, start_timestamp, profiles);
+ parent_collector_->Collect(params, start_timestamp, std::move(profiles));
} else if (retain_profiles_) {
- profiles_.push_back(ProfilesState(params, start_timestamp, profiles));
+ profiles_.push_back(
+ ProfilesState(params, start_timestamp, std::move(profiles)));
}
}

Powered by Google App Engine
This is Rietveld 408576698