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

Unified Diff: base/profiler/stack_sampling_profiler.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
« no previous file with comments | « base/profiler/stack_sampling_profiler.h ('k') | base/profiler/stack_sampling_profiler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e25440f80c56b32896b0f018b38e2514086f933d 100644
--- a/base/profiler/stack_sampling_profiler.cc
+++ b/base/profiler/stack_sampling_profiler.cc
@@ -40,12 +40,13 @@ class AsyncRunner {
private:
AsyncRunner();
- // Runs the callback and deletes the AsyncRunner instance.
+ // Runs the callback and deletes the AsyncRunner instance. |profiles| is not
+ // const& because it must be passed with std::move.
static void RunCallbackAndDeleteInstance(
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 +76,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());
}
@@ -110,10 +111,22 @@ StackSamplingProfiler::Frame::Frame()
StackSamplingProfiler::CallStackProfile::CallStackProfile() {}
StackSamplingProfiler::CallStackProfile::CallStackProfile(
- const CallStackProfile& other) = default;
+ CallStackProfile&& other) = default;
StackSamplingProfiler::CallStackProfile::~CallStackProfile() {}
+StackSamplingProfiler::CallStackProfile&
+StackSamplingProfiler::CallStackProfile::operator=(CallStackProfile&& other) =
+ default;
+
+StackSamplingProfiler::CallStackProfile
+StackSamplingProfiler::CallStackProfile::CopyForTesting() const {
+ return CallStackProfile(*this);
+}
+
+StackSamplingProfiler::CallStackProfile::CallStackProfile(
+ const CallStackProfile& other) = default;
+
// StackSamplingProfiler::SamplingThread --------------------------------------
StackSamplingProfiler::SamplingThread::SamplingThread(
@@ -139,7 +152,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 +216,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;
« no previous file with comments | « base/profiler/stack_sampling_profiler.h ('k') | base/profiler/stack_sampling_profiler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698