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

Unified Diff: Source/core/page/animation/KeyframeAnimation.cpp

Issue 14189015: KeyframeAnimation::fetchIntervalEndpointsForProperty could use binary search to lookup keyframes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/animation/KeyframeAnimation.cpp
diff --git a/Source/core/page/animation/KeyframeAnimation.cpp b/Source/core/page/animation/KeyframeAnimation.cpp
index dcba2d9a13fc49ec5eb3f454267770c6711eae9a..43f38a7620aa4f6ba52c8f04a95de030e53b37b4 100644
--- a/Source/core/page/animation/KeyframeAnimation.cpp
+++ b/Source/core/page/animation/KeyframeAnimation.cpp
@@ -97,22 +97,47 @@ void KeyframeAnimation::fetchIntervalEndpointsForProperty(CSSPropertyID property
ASSERT(!m_keyframes[0].key());
ASSERT(m_keyframes[m_keyframes.size() - 1].key() == 1);
+ size_t currentIndex = 0;
+ size_t firstIndex = 0;
+ size_t lastIndex = numKeyframes - 1;
+ size_t distance = numKeyframes;
+
+ // Find keyframe that is closest to elapsed time.
+ while (distance > 1) {
+ currentIndex = (lastIndex + firstIndex) >> 1;
+ float key = m_keyframes[currentIndex].key();
+ distance = lastIndex - currentIndex;
+
+ if (key == fractionalTime)
apavlov 2013/04/22 14:23:02 I think this will _rarely_ be true, as you are com
+ break;
+
+ if (key < fractionalTime) {
+ if (distance < 2)
+ currentIndex++;
+ firstIndex = currentIndex;
+ } else
+ lastIndex = currentIndex;
+ }
+
int prevIndex = -1;
int nextIndex = -1;
-
- // FIXME: with a lot of keys, this linear search will be slow. We could binary search.
- for (size_t i = 0; i < numKeyframes; ++i) {
- const KeyframeValue& currKeyFrame = m_keyframes[i];
- if (!currKeyFrame.containsProperty(property))
- continue;
-
- if (fractionalTime < currKeyFrame.key()) {
+ // Interate forward to find next keyframe that is used to animate CSS property.
+ for (size_t i = currentIndex; i < numKeyframes; ++i) {
+ const KeyframeValue& keyFrame = m_keyframes[i];
+ if (keyFrame.containsProperty(property) && keyFrame.key() > fractionalTime) {
nextIndex = i;
break;
}
-
- prevIndex = i;
+ }
+
+ // Interate backward to find previous keyframe.
+ for (size_t i = currentIndex; i < numKeyframes; --i) {
apavlov 2013/04/22 14:23:02 The condition should definitely be "i >= 0"
+ const KeyframeValue& keyFrame = m_keyframes[i];
+ if (keyFrame.containsProperty(property) && keyFrame.key() <= fractionalTime) {
+ prevIndex = i;
+ break;
+ }
}
double scale = 1;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698