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

Unified Diff: cc/animation/animation_host.cc

Issue 1814103002: CC Animation: Use unordered_map instead of vector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use move semantics on insertions. Created 4 years, 9 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 | « cc/animation/animation_host.h ('k') | cc/animation/animation_timeline.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/animation/animation_host.cc
diff --git a/cc/animation/animation_host.cc b/cc/animation/animation_host.cc
index 7e6188f39703f62499d383987d94051ceda6a165..61a24a9d223f388c721e23a3e62fc708b488b0c9 100644
--- a/cc/animation/animation_host.cc
+++ b/cc/animation/animation_host.cc
@@ -167,42 +167,34 @@ AnimationHost::~AnimationHost() {
}
AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const {
- for (auto& timeline : timelines_)
- if (timeline->id() == timeline_id)
- return timeline.get();
- return nullptr;
+ auto f = id_to_timeline_map_.find(timeline_id);
+ return f == id_to_timeline_map_.end() ? nullptr : f->second.get();
}
void AnimationHost::ClearTimelines() {
- EraseTimelines(timelines_.begin(), timelines_.end());
+ for (auto& kv : id_to_timeline_map_)
+ EraseTimeline(kv.second);
+ id_to_timeline_map_.clear();
}
-void AnimationHost::EraseTimelines(AnimationTimelineList::iterator begin,
- AnimationTimelineList::iterator end) {
- for (auto i = begin; i != end; ++i) {
- auto& timeline = *i;
- timeline->ClearPlayers();
- timeline->SetAnimationHost(nullptr);
- }
-
- timelines_.erase(begin, end);
+void AnimationHost::EraseTimeline(scoped_refptr<AnimationTimeline> timeline) {
+ timeline->ClearPlayers();
+ timeline->SetAnimationHost(nullptr);
}
void AnimationHost::AddAnimationTimeline(
scoped_refptr<AnimationTimeline> timeline) {
+ DCHECK(timeline->id());
timeline->SetAnimationHost(this);
- timelines_.push_back(timeline);
+ id_to_timeline_map_.insert(
+ std::make_pair(timeline->id(), std::move(timeline)));
}
void AnimationHost::RemoveAnimationTimeline(
scoped_refptr<AnimationTimeline> timeline) {
- for (auto iter = timelines_.begin(); iter != timelines_.end(); ++iter) {
- if (iter->get() != timeline)
- continue;
-
- EraseTimelines(iter, iter + 1);
- break;
- }
+ DCHECK(timeline->id());
+ EraseTimeline(timeline);
+ id_to_timeline_map_.erase(timeline->id());
}
void AnimationHost::RegisterLayer(int layer_id, LayerTreeType tree_type) {
@@ -280,7 +272,8 @@ void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) {
}
void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const {
- for (auto& timeline : timelines_) {
+ for (auto& kv : id_to_timeline_map_) {
+ auto& timeline = kv.second;
AnimationTimeline* timeline_impl =
host_impl->GetTimelineById(timeline->id());
if (timeline_impl)
@@ -293,22 +286,25 @@ void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const {
void AnimationHost::RemoveTimelinesFromImplThread(
AnimationHost* host_impl) const {
- AnimationTimelineList& timelines_impl = host_impl->timelines_;
-
- auto to_erase =
- std::partition(timelines_impl.begin(), timelines_impl.end(),
- [this](AnimationTimelineList::value_type timeline_impl) {
- return timeline_impl->is_impl_only() ||
- GetTimelineById(timeline_impl->id());
- });
-
- host_impl->EraseTimelines(to_erase, timelines_impl.end());
+ IdToTimelineMap& timelines_impl = host_impl->id_to_timeline_map_;
+
+ // Erase all the impl timelines which |this| doesn't have.
+ for (auto it = timelines_impl.begin(); it != timelines_impl.end();) {
+ auto& timeline_impl = it->second;
+ if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) {
+ ++it;
+ } else {
+ host_impl->EraseTimeline(it->second);
+ it = timelines_impl.erase(it);
+ }
+ }
}
void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) {
// Firstly, sync all players with impl thread to create ElementAnimations and
// layer animation controllers.
- for (auto& timeline : timelines_) {
+ for (auto& kv : id_to_timeline_map_) {
+ AnimationTimeline* timeline = kv.second.get();
AnimationTimeline* timeline_impl =
host_impl->GetTimelineById(timeline->id());
if (timeline_impl)
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_timeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698