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

Side by Side Diff: cc/debug/micro_benchmark_controller.cc

Issue 1437413002: cc: Remove ScopedPtrVector and cc::remove_if. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/debug/micro_benchmark_controller.h" 5 #include "cc/debug/micro_benchmark_controller.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 19 matching lines...) Expand all
30 return make_scoped_ptr(new InvalidationBenchmark(value.Pass(), callback)); 30 return make_scoped_ptr(new InvalidationBenchmark(value.Pass(), callback));
31 } else if (name == "rasterize_and_record_benchmark") { 31 } else if (name == "rasterize_and_record_benchmark") {
32 return make_scoped_ptr( 32 return make_scoped_ptr(
33 new RasterizeAndRecordBenchmark(value.Pass(), callback)); 33 new RasterizeAndRecordBenchmark(value.Pass(), callback));
34 } else if (name == "unittest_only_benchmark") { 34 } else if (name == "unittest_only_benchmark") {
35 return make_scoped_ptr(new UnittestOnlyBenchmark(value.Pass(), callback)); 35 return make_scoped_ptr(new UnittestOnlyBenchmark(value.Pass(), callback));
36 } 36 }
37 return nullptr; 37 return nullptr;
38 } 38 }
39 39
40 class IsDonePredicate {
41 public:
42 typedef const MicroBenchmark* argument_type;
43 typedef bool result_type;
44
45 result_type operator()(argument_type benchmark) const {
46 return benchmark->IsDone();
47 }
48 };
49
50 } // namespace 40 } // namespace
51 41
52 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) 42 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host)
53 : host_(host), 43 : host_(host),
54 main_controller_task_runner_(base::ThreadTaskRunnerHandle::IsSet() 44 main_controller_task_runner_(base::ThreadTaskRunnerHandle::IsSet()
55 ? base::ThreadTaskRunnerHandle::Get() 45 ? base::ThreadTaskRunnerHandle::Get()
56 : nullptr) { 46 : nullptr) {
57 DCHECK(host_); 47 DCHECK(host_);
58 } 48 }
59 49
(...skipping 18 matching lines...) Expand all
78 int MicroBenchmarkController::GetNextIdAndIncrement() { 68 int MicroBenchmarkController::GetNextIdAndIncrement() {
79 int id = next_id_++; 69 int id = next_id_++;
80 // Wrap around to 1 if we overflow (very unlikely). 70 // Wrap around to 1 if we overflow (very unlikely).
81 if (next_id_ == std::numeric_limits<int>::max()) 71 if (next_id_ == std::numeric_limits<int>::max())
82 next_id_ = 1; 72 next_id_ = 1;
83 return id; 73 return id;
84 } 74 }
85 75
86 bool MicroBenchmarkController::SendMessage(int id, 76 bool MicroBenchmarkController::SendMessage(int id,
87 scoped_ptr<base::Value> value) { 77 scoped_ptr<base::Value> value) {
88 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); 78 auto it = std::find_if(benchmarks_.begin(), benchmarks_.end(),
89 it != benchmarks_.end(); 79 [id](const scoped_ptr<MicroBenchmark>& benchmark) {
90 ++it) { 80 return benchmark->id() == id;
91 if ((*it)->id() == id) 81 });
92 return (*it)->ProcessMessage(value.Pass()); 82 return it != benchmarks_.end() ? (*it)->ProcessMessage(value.Pass()) : false;
danakj 2015/11/17 23:49:41 can you do this with an early out instead on if it
vmpstr 2015/11/18 00:08:46 Done.
93 }
94 return false;
95 } 83 }
96 84
97 void MicroBenchmarkController::ScheduleImplBenchmarks( 85 void MicroBenchmarkController::ScheduleImplBenchmarks(
98 LayerTreeHostImpl* host_impl) { 86 LayerTreeHostImpl* host_impl) {
99 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); 87 for (const auto& benchmark : benchmarks_) {
100 it != benchmarks_.end();
101 ++it) {
102 scoped_ptr<MicroBenchmarkImpl> benchmark_impl; 88 scoped_ptr<MicroBenchmarkImpl> benchmark_impl;
103 if (!(*it)->ProcessedForBenchmarkImpl()) { 89 if (!benchmark->ProcessedForBenchmarkImpl()) {
104 benchmark_impl = (*it)->GetBenchmarkImpl(main_controller_task_runner_); 90 benchmark_impl =
91 benchmark->GetBenchmarkImpl(main_controller_task_runner_);
105 } 92 }
106 93
107 if (benchmark_impl.get()) 94 if (benchmark_impl.get())
108 host_impl->ScheduleMicroBenchmark(benchmark_impl.Pass()); 95 host_impl->ScheduleMicroBenchmark(benchmark_impl.Pass());
109 } 96 }
110 } 97 }
111 98
112 void MicroBenchmarkController::DidUpdateLayers() { 99 void MicroBenchmarkController::DidUpdateLayers() {
113 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); 100 for (const auto& benchmark : benchmarks_) {
114 it != benchmarks_.end(); 101 if (!benchmark->IsDone())
115 ++it) { 102 benchmark->DidUpdateLayers(host_);
116 if (!(*it)->IsDone())
117 (*it)->DidUpdateLayers(host_);
118 } 103 }
119 104
120 CleanUpFinishedBenchmarks(); 105 CleanUpFinishedBenchmarks();
121 } 106 }
122 107
123 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { 108 void MicroBenchmarkController::CleanUpFinishedBenchmarks() {
124 benchmarks_.erase( 109 benchmarks_.erase(
125 benchmarks_.partition(std::not1(IsDonePredicate())), 110 std::remove_if(benchmarks_.begin(), benchmarks_.end(),
111 [](const scoped_ptr<MicroBenchmark>& benchmark) {
112 return benchmark->IsDone();
113 }),
126 benchmarks_.end()); 114 benchmarks_.end());
127 } 115 }
128 116
129 } // namespace cc 117 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698