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

Unified Diff: third_party/WebKit/Source/core/fetch/ImageResource.cpp

Issue 2555103004: ImageResource: remove unnecessary vector copying during iteration. (Closed)
Patch Set: add comment Created 4 years 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 | third_party/WebKit/Source/core/fetch/ImageResourceObserver.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/fetch/ImageResource.cpp
diff --git a/third_party/WebKit/Source/core/fetch/ImageResource.cpp b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
index 0a454391815e5909ea81d4e931931a92341c7884..0179fe984a9747eb4a7a2db35e83c885bd778db5 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
@@ -156,10 +156,11 @@ void ImageResource::checkNotify() {
}
void ImageResource::markObserverFinished(ImageResourceObserver* observer) {
- if (m_observers.contains(observer)) {
- m_finishedObservers.add(observer);
- m_observers.remove(observer);
- }
+ auto it = m_observers.find(observer);
+ if (it == m_observers.end())
+ return;
+ m_observers.remove(it);
+ m_finishedObservers.add(observer);
}
void ImageResource::didAddClient(ResourceClient* client) {
@@ -205,13 +206,14 @@ void ImageResource::addObserver(ImageResourceObserver* observer) {
void ImageResource::removeObserver(ImageResourceObserver* observer) {
DCHECK(observer);
- if (m_observers.contains(observer))
- m_observers.remove(observer);
- else if (m_finishedObservers.contains(observer))
- m_finishedObservers.remove(observer);
- else
- NOTREACHED();
-
+ auto it = m_observers.find(observer);
+ if (it != m_observers.end()) {
+ m_observers.remove(it);
+ } else {
+ it = m_finishedObservers.find(observer);
+ DCHECK(it != m_finishedObservers.end());
+ m_finishedObservers.remove(it);
+ }
didRemoveClientOrObserver();
}
@@ -227,14 +229,10 @@ static void priorityFromObserver(const ImageResourceObserver* observer,
ResourcePriority ImageResource::priorityFromObservers() {
ResourcePriority priority;
- for (auto* observer : m_finishedObservers.asVector()) {
- if (m_finishedObservers.contains(observer))
- priorityFromObserver(observer, priority);
- }
- for (auto* observer : m_observers.asVector()) {
- if (m_observers.contains(observer))
- priorityFromObserver(observer, priority);
- }
+ for (const auto& it : m_finishedObservers)
+ priorityFromObserver(it.key, priority);
+ for (const auto& it : m_observers)
+ priorityFromObserver(it.key, priority);
return priority;
}
@@ -579,15 +577,13 @@ bool ImageResource::shouldPauseAnimation(const blink::Image* image) {
if (!image || image != m_image)
return false;
- for (auto* observer : m_finishedObservers.asVector()) {
- if (m_finishedObservers.contains(observer) && observer->willRenderImage())
+ for (const auto& it : m_finishedObservers)
+ if (it.key->willRenderImage())
return false;
- }
- for (auto* observer : m_observers.asVector()) {
- if (m_observers.contains(observer) && observer->willRenderImage())
+ for (const auto& it : m_observers)
+ if (it.key->willRenderImage())
return false;
- }
return true;
}
@@ -603,14 +599,12 @@ void ImageResource::updateImageAnimationPolicy() {
return;
ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed;
- for (auto* observer : m_finishedObservers.asVector()) {
- if (m_finishedObservers.contains(observer) &&
- observer->getImageAnimationPolicy(newPolicy))
+ for (const auto& it : m_finishedObservers) {
+ if (it.key->getImageAnimationPolicy(newPolicy))
break;
}
- for (auto* observer : m_observers.asVector()) {
- if (m_observers.contains(observer) &&
- observer->getImageAnimationPolicy(newPolicy))
+ for (const auto& it : m_observers) {
+ if (it.key->getImageAnimationPolicy(newPolicy))
break;
}
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/fetch/ImageResourceObserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698