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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/fetch/ImageResourceObserver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 void ImageResource::checkNotify() { 149 void ImageResource::checkNotify() {
150 // Don't notify clients of completion if this ImageResource is 150 // Don't notify clients of completion if this ImageResource is
151 // about to be reloaded. 151 // about to be reloaded.
152 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder()) 152 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder())
153 return; 153 return;
154 154
155 Resource::checkNotify(); 155 Resource::checkNotify();
156 } 156 }
157 157
158 void ImageResource::markObserverFinished(ImageResourceObserver* observer) { 158 void ImageResource::markObserverFinished(ImageResourceObserver* observer) {
159 if (m_observers.contains(observer)) { 159 auto it = m_observers.find(observer);
160 m_finishedObservers.add(observer); 160 if (it == m_observers.end())
161 m_observers.remove(observer); 161 return;
162 } 162 m_observers.remove(it);
163 m_finishedObservers.add(observer);
163 } 164 }
164 165
165 void ImageResource::didAddClient(ResourceClient* client) { 166 void ImageResource::didAddClient(ResourceClient* client) {
166 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); 167 DCHECK((m_multipartParser && isLoading()) || !data() || m_image);
167 168
168 // Don't notify observers and clients of completion if this ImageResource is 169 // Don't notify observers and clients of completion if this ImageResource is
169 // about to be reloaded. 170 // about to be reloaded.
170 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder()) 171 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder())
171 return; 172 return;
172 173
(...skipping 25 matching lines...) Expand all
198 if (isLoaded() && m_observers.contains(observer) && !m_isSchedulingReload && 199 if (isLoaded() && m_observers.contains(observer) && !m_isSchedulingReload &&
199 !shouldReloadBrokenPlaceholder()) { 200 !shouldReloadBrokenPlaceholder()) {
200 markObserverFinished(observer); 201 markObserverFinished(observer);
201 observer->imageNotifyFinished(this); 202 observer->imageNotifyFinished(this);
202 } 203 }
203 } 204 }
204 205
205 void ImageResource::removeObserver(ImageResourceObserver* observer) { 206 void ImageResource::removeObserver(ImageResourceObserver* observer) {
206 DCHECK(observer); 207 DCHECK(observer);
207 208
208 if (m_observers.contains(observer)) 209 auto it = m_observers.find(observer);
209 m_observers.remove(observer); 210 if (it != m_observers.end()) {
210 else if (m_finishedObservers.contains(observer)) 211 m_observers.remove(it);
211 m_finishedObservers.remove(observer); 212 } else {
212 else 213 it = m_finishedObservers.find(observer);
213 NOTREACHED(); 214 DCHECK(it != m_finishedObservers.end());
214 215 m_finishedObservers.remove(it);
216 }
215 didRemoveClientOrObserver(); 217 didRemoveClientOrObserver();
216 } 218 }
217 219
218 static void priorityFromObserver(const ImageResourceObserver* observer, 220 static void priorityFromObserver(const ImageResourceObserver* observer,
219 ResourcePriority& priority) { 221 ResourcePriority& priority) {
220 ResourcePriority nextPriority = observer->computeResourcePriority(); 222 ResourcePriority nextPriority = observer->computeResourcePriority();
221 if (nextPriority.visibility == ResourcePriority::NotVisible) 223 if (nextPriority.visibility == ResourcePriority::NotVisible)
222 return; 224 return;
223 priority.visibility = ResourcePriority::Visible; 225 priority.visibility = ResourcePriority::Visible;
224 priority.intraPriorityValue += nextPriority.intraPriorityValue; 226 priority.intraPriorityValue += nextPriority.intraPriorityValue;
225 } 227 }
226 228
227 ResourcePriority ImageResource::priorityFromObservers() { 229 ResourcePriority ImageResource::priorityFromObservers() {
228 ResourcePriority priority; 230 ResourcePriority priority;
229 231
230 for (auto* observer : m_finishedObservers.asVector()) { 232 for (const auto& it : m_finishedObservers)
231 if (m_finishedObservers.contains(observer)) 233 priorityFromObserver(it.key, priority);
232 priorityFromObserver(observer, priority); 234 for (const auto& it : m_observers)
233 } 235 priorityFromObserver(it.key, priority);
234 for (auto* observer : m_observers.asVector()) {
235 if (m_observers.contains(observer))
236 priorityFromObserver(observer, priority);
237 }
238 236
239 return priority; 237 return priority;
240 } 238 }
241 239
242 void ImageResource::destroyDecodedDataForFailedRevalidation() { 240 void ImageResource::destroyDecodedDataForFailedRevalidation() {
243 clearImage(); 241 clearImage();
244 setDecodedSize(0); 242 setDecodedSize(0);
245 } 243 }
246 244
247 void ImageResource::destroyDecodedDataIfPossible() { 245 void ImageResource::destroyDecodedDataIfPossible() {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 if (!image || image != m_image) 570 if (!image || image != m_image)
573 return; 571 return;
574 572
575 setDecodedSize(newSize); 573 setDecodedSize(newSize);
576 } 574 }
577 575
578 bool ImageResource::shouldPauseAnimation(const blink::Image* image) { 576 bool ImageResource::shouldPauseAnimation(const blink::Image* image) {
579 if (!image || image != m_image) 577 if (!image || image != m_image)
580 return false; 578 return false;
581 579
582 for (auto* observer : m_finishedObservers.asVector()) { 580 for (const auto& it : m_finishedObservers)
583 if (m_finishedObservers.contains(observer) && observer->willRenderImage()) 581 if (it.key->willRenderImage())
584 return false; 582 return false;
585 }
586 583
587 for (auto* observer : m_observers.asVector()) { 584 for (const auto& it : m_observers)
588 if (m_observers.contains(observer) && observer->willRenderImage()) 585 if (it.key->willRenderImage())
589 return false; 586 return false;
590 }
591 587
592 return true; 588 return true;
593 } 589 }
594 590
595 void ImageResource::animationAdvanced(const blink::Image* image) { 591 void ImageResource::animationAdvanced(const blink::Image* image) {
596 if (!image || image != m_image) 592 if (!image || image != m_image)
597 return; 593 return;
598 notifyObservers(DoNotNotifyFinish); 594 notifyObservers(DoNotNotifyFinish);
599 } 595 }
600 596
601 void ImageResource::updateImageAnimationPolicy() { 597 void ImageResource::updateImageAnimationPolicy() {
602 if (!m_image) 598 if (!m_image)
603 return; 599 return;
604 600
605 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; 601 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed;
606 for (auto* observer : m_finishedObservers.asVector()) { 602 for (const auto& it : m_finishedObservers) {
607 if (m_finishedObservers.contains(observer) && 603 if (it.key->getImageAnimationPolicy(newPolicy))
608 observer->getImageAnimationPolicy(newPolicy))
609 break; 604 break;
610 } 605 }
611 for (auto* observer : m_observers.asVector()) { 606 for (const auto& it : m_observers) {
612 if (m_observers.contains(observer) && 607 if (it.key->getImageAnimationPolicy(newPolicy))
613 observer->getImageAnimationPolicy(newPolicy))
614 break; 608 break;
615 } 609 }
616 610
617 if (m_image->animationPolicy() != newPolicy) { 611 if (m_image->animationPolicy() != newPolicy) {
618 m_image->resetAnimation(); 612 m_image->resetAnimation();
619 m_image->setAnimationPolicy(newPolicy); 613 m_image->setAnimationPolicy(newPolicy);
620 } 614 }
621 } 615 }
622 616
623 static bool isLoFiImage(const ImageResource& resource) { 617 static bool isLoFiImage(const ImageResource& resource) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 WebServiceWorkerResponseTypeOpaque; 707 WebServiceWorkerResponseTypeOpaque;
714 } 708 }
715 if (!getImage()->currentFrameHasSingleSecurityOrigin()) 709 if (!getImage()->currentFrameHasSingleSecurityOrigin())
716 return false; 710 return false;
717 if (passesAccessControlCheck(securityOrigin)) 711 if (passesAccessControlCheck(securityOrigin))
718 return true; 712 return true;
719 return !securityOrigin->taintsCanvas(response().url()); 713 return !securityOrigin->taintsCanvas(response().url());
720 } 714 }
721 715
722 } // namespace blink 716 } // namespace blink
OLDNEW
« 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