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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 1852423003: Avoid unnecessary DocumentElementSetMap hash table updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | 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) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // Default to not logging warnings about excessive drift in the cached media tim e because it adds a 100 // Default to not logging warnings about excessive drift in the cached media tim e because it adds a
101 // fair amount of overhead and logging. 101 // fair amount of overhead and logging.
102 #define LOG_CACHED_TIME_WARNINGS 0 102 #define LOG_CACHED_TIME_WARNINGS 0
103 #endif 103 #endif
104 104
105 namespace blink { 105 namespace blink {
106 106
107 using namespace HTMLNames; 107 using namespace HTMLNames;
108 108
109 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>; 109 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>;
110 using DocumentElementSetMap = HeapHashMap<WeakMember<Document>, WeakMediaElement Set>; 110 using DocumentElementSetMap = HeapHashMap<WeakMember<Document>, Member<WeakMedia ElementSet>>;
111 111
112 namespace { 112 namespace {
113 113
114 // URL protocol used to signal that the media source API is being used. 114 // URL protocol used to signal that the media source API is being used.
115 const char mediaSourceBlobProtocol[] = "blob"; 115 const char mediaSourceBlobProtocol[] = "blob";
116 116
117 enum MediaControlsShow { 117 enum MediaControlsShow {
118 MediaControlsShowAttribute = 0, 118 MediaControlsShowAttribute = 0,
119 MediaControlsShowFullscreen, 119 MediaControlsShowFullscreen,
120 MediaControlsShowNoScript, 120 MediaControlsShowNoScript,
(...skipping 19 matching lines...) Expand all
140 140
141 DocumentElementSetMap& documentToElementSetMap() 141 DocumentElementSetMap& documentToElementSetMap()
142 { 142 {
143 DEFINE_STATIC_LOCAL(DocumentElementSetMap, map, (new DocumentElementSetMap)) ; 143 DEFINE_STATIC_LOCAL(DocumentElementSetMap, map, (new DocumentElementSetMap)) ;
144 return map; 144 return map;
145 } 145 }
146 146
147 void addElementToDocumentMap(HTMLMediaElement* element, Document* document) 147 void addElementToDocumentMap(HTMLMediaElement* element, Document* document)
148 { 148 {
149 DocumentElementSetMap& map = documentToElementSetMap(); 149 DocumentElementSetMap& map = documentToElementSetMap();
150 WeakMediaElementSet set = map.take(document); 150 WeakMediaElementSet* set = nullptr;
151 set.add(element); 151 auto it = map.find(document);
152 map.add(document, set); 152 if (it == map.end()) {
153 set = new WeakMediaElementSet;
154 map.add(document, set);
155 } else {
156 set = it->value;
157 }
158 set->add(element);
153 } 159 }
154 160
155 void removeElementFromDocumentMap(HTMLMediaElement* element, Document* document) 161 void removeElementFromDocumentMap(HTMLMediaElement* element, Document* document)
156 { 162 {
157 DocumentElementSetMap& map = documentToElementSetMap(); 163 DocumentElementSetMap& map = documentToElementSetMap();
158 WeakMediaElementSet set = map.take(document); 164 auto it = map.find(document);
159 set.remove(element); 165 ASSERT(it != map.end());
160 if (!set.isEmpty()) 166 WeakMediaElementSet* set = it->value;
161 map.add(document, set); 167 set->remove(element);
168 if (set->isEmpty())
169 map.remove(it);
162 } 170 }
163 171
164 class AudioSourceProviderClientLockScope { 172 class AudioSourceProviderClientLockScope {
165 STACK_ALLOCATED(); 173 STACK_ALLOCATED();
166 public: 174 public:
167 AudioSourceProviderClientLockScope(HTMLMediaElement& element) 175 AudioSourceProviderClientLockScope(HTMLMediaElement& element)
168 : m_client(element.audioSourceNode()) 176 : m_client(element.audioSourceNode())
169 { 177 {
170 if (m_client) 178 if (m_client)
171 m_client->lock(); 179 m_client->lock();
(...skipping 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after
3349 m_processingPreferenceChange = false; 3357 m_processingPreferenceChange = false;
3350 3358
3351 // As track visibility changed while m_processingPreferenceChange was set, 3359 // As track visibility changed while m_processingPreferenceChange was set,
3352 // there was no call to updateTextTrackDisplay(). This call is not in the 3360 // there was no call to updateTextTrackDisplay(). This call is not in the
3353 // spec, see the note in configureTextTrackDisplay(). 3361 // spec, see the note in configureTextTrackDisplay().
3354 updateTextTrackDisplay(); 3362 updateTextTrackDisplay();
3355 } 3363 }
3356 3364
3357 void HTMLMediaElement::setTextTrackKindUserPreferenceForAllMediaElements(Documen t* document) 3365 void HTMLMediaElement::setTextTrackKindUserPreferenceForAllMediaElements(Documen t* document)
3358 { 3366 {
3359 WeakMediaElementSet elements = documentToElementSetMap().get(document); 3367 auto it = documentToElementSetMap().find(document);
3368 if (it == documentToElementSetMap().end())
3369 return;
3370 ASSERT(it->value);
3371 WeakMediaElementSet& elements = *it->value;
3360 for (const auto& element : elements) 3372 for (const auto& element : elements)
3361 element->automaticTrackSelectionForUpdatedUserPreference(); 3373 element->automaticTrackSelectionForUpdatedUserPreference();
3362 } 3374 }
3363 3375
3364 void HTMLMediaElement::automaticTrackSelectionForUpdatedUserPreference() 3376 void HTMLMediaElement::automaticTrackSelectionForUpdatedUserPreference()
3365 { 3377 {
3366 if (!m_textTracks || !m_textTracks->length()) 3378 if (!m_textTracks || !m_textTracks->length())
3367 return; 3379 return;
3368 3380
3369 markCaptionAndSubtitleTracksAsUnconfigured(); 3381 markCaptionAndSubtitleTracksAsUnconfigured();
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
3870 } 3882 }
3871 3883
3872 #if !ENABLE(OILPAN) 3884 #if !ENABLE(OILPAN)
3873 WeakPtr<HTMLMediaElement> HTMLMediaElement::createWeakPtr() 3885 WeakPtr<HTMLMediaElement> HTMLMediaElement::createWeakPtr()
3874 { 3886 {
3875 return m_weakPtrFactory.createWeakPtr(); 3887 return m_weakPtrFactory.createWeakPtr();
3876 } 3888 }
3877 #endif 3889 #endif
3878 3890
3879 } // namespace blink 3891 } // namespace blink
OLDNEW
« 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