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

Unified 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 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: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
index 0e2c06a7a470142e4c48b90c2d8472efc7d1dd6d..06d4a93b6dfca9cb3d42b26427ecb7be2d3f6673 100644
--- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
@@ -107,7 +107,7 @@ namespace blink {
using namespace HTMLNames;
using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>;
-using DocumentElementSetMap = HeapHashMap<WeakMember<Document>, WeakMediaElementSet>;
+using DocumentElementSetMap = HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>;
namespace {
@@ -147,18 +147,26 @@ DocumentElementSetMap& documentToElementSetMap()
void addElementToDocumentMap(HTMLMediaElement* element, Document* document)
{
DocumentElementSetMap& map = documentToElementSetMap();
- WeakMediaElementSet set = map.take(document);
- set.add(element);
- map.add(document, set);
+ WeakMediaElementSet* set = nullptr;
+ auto it = map.find(document);
+ if (it == map.end()) {
+ set = new WeakMediaElementSet;
+ map.add(document, set);
+ } else {
+ set = it->value;
+ }
+ set->add(element);
}
void removeElementFromDocumentMap(HTMLMediaElement* element, Document* document)
{
DocumentElementSetMap& map = documentToElementSetMap();
- WeakMediaElementSet set = map.take(document);
- set.remove(element);
- if (!set.isEmpty())
- map.add(document, set);
+ auto it = map.find(document);
+ ASSERT(it != map.end());
+ WeakMediaElementSet* set = it->value;
+ set->remove(element);
+ if (set->isEmpty())
+ map.remove(it);
}
class AudioSourceProviderClientLockScope {
@@ -3356,7 +3364,11 @@ void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
void HTMLMediaElement::setTextTrackKindUserPreferenceForAllMediaElements(Document* document)
{
- WeakMediaElementSet elements = documentToElementSetMap().get(document);
+ auto it = documentToElementSetMap().find(document);
+ if (it == documentToElementSetMap().end())
+ return;
+ ASSERT(it->value);
+ WeakMediaElementSet& elements = *it->value;
for (const auto& element : elements)
element->automaticTrackSelectionForUpdatedUserPreference();
}
« 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