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

Unified Diff: base/profiler/stack_sampling_profiler.cc

Issue 2438073002: Use movable types for CallStackProfile(s) to remove copying of data. (Closed)
Patch Set: fix tests and build problems 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: base/profiler/stack_sampling_profiler.cc
diff --git a/base/profiler/stack_sampling_profiler.cc b/base/profiler/stack_sampling_profiler.cc
index 538368bd23f6fd63d25dfefa6e6ea68f5a785208..fa6544a4c1d4aa3afcf0d0ec497226e1d6adbb24 100644
--- a/base/profiler/stack_sampling_profiler.cc
+++ b/base/profiler/stack_sampling_profiler.cc
@@ -45,7 +45,7 @@ class AsyncRunner {
std::unique_ptr<AsyncRunner> object_to_be_deleted,
const StackSamplingProfiler::CompletedCallback& callback,
scoped_refptr<SingleThreadTaskRunner> task_runner,
- const StackSamplingProfiler::CallStackProfiles& profiles);
+ StackSamplingProfiler::CallStackProfiles profiles);
std::unique_ptr<StackSamplingProfiler> profiler_;
@@ -75,8 +75,8 @@ void AsyncRunner::RunCallbackAndDeleteInstance(
std::unique_ptr<AsyncRunner> object_to_be_deleted,
const StackSamplingProfiler::CompletedCallback& callback,
scoped_refptr<SingleThreadTaskRunner> task_runner,
- const StackSamplingProfiler::CallStackProfiles& profiles) {
- callback.Run(profiles);
+ StackSamplingProfiler::CallStackProfiles profiles) {
+ callback.Run(std::move(profiles));
// Delete the instance on the original calling thread.
task_runner->DeleteSoon(FROM_HERE, object_to_be_deleted.release());
}
@@ -112,8 +112,20 @@ StackSamplingProfiler::CallStackProfile::CallStackProfile() {}
StackSamplingProfiler::CallStackProfile::CallStackProfile(
const CallStackProfile& other) = default;
Mike Wittman 2016/10/21 18:05:29 nit: function order (this should be last)
bcwhite 2016/10/24 13:17:45 Done.
+StackSamplingProfiler::CallStackProfile::CallStackProfile(
+ CallStackProfile&& other) = default;
+
StackSamplingProfiler::CallStackProfile::~CallStackProfile() {}
+StackSamplingProfiler::CallStackProfile&
+StackSamplingProfiler::CallStackProfile::operator=(CallStackProfile&& other) =
+ default;
+
+StackSamplingProfiler::CallStackProfile
+StackSamplingProfiler::CallStackProfile::CopyForTesting() const {
+ return CallStackProfile(*this);
+}
+
// StackSamplingProfiler::SamplingThread --------------------------------------
StackSamplingProfiler::SamplingThread::SamplingThread(
@@ -139,7 +151,7 @@ void StackSamplingProfiler::SamplingThread::ThreadMain() {
CallStackProfiles profiles;
CollectProfiles(&profiles);
concurrent_profiling_lock.Get().Release();
- completed_callback_.Run(profiles);
+ completed_callback_.Run(std::move(profiles));
}
// Depending on how long the sampling takes and the length of the sampling
@@ -203,7 +215,7 @@ void StackSamplingProfiler::SamplingThread::CollectProfiles(
bool was_stopped = false;
CollectProfile(&profile, &previous_elapsed_profile_time, &was_stopped);
if (!profile.samples.empty())
- profiles->push_back(profile);
+ profiles->push_back(std::move(profile));
if (was_stopped)
return;

Powered by Google App Engine
This is Rietveld 408576698