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

Side by Side Diff: Source/core/dom/custom/CustomElementUpgradeCandidateMap.cpp

Issue 296703009: Oilpan: move custom element objects to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use LinkedHashSet for ElementSet instead. Created 6 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/dom/custom/CustomElementUpgradeCandidateMap.h" 32 #include "core/dom/custom/CustomElementUpgradeCandidateMap.h"
33 33
34 #include "core/dom/Element.h" 34 #include "core/dom/Element.h"
35 35
36 namespace WebCore { 36 namespace WebCore {
37 37
38 PassOwnPtrWillBeRawPtr<CustomElementUpgradeCandidateMap> CustomElementUpgradeCan didateMap::create()
39 {
40 return adoptPtrWillBeNoop(new CustomElementUpgradeCandidateMap());
41 }
42
38 CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap() 43 CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap()
39 { 44 {
45 #if !ENABLE(OILPAN)
46 // With Oilpan enabled, the observer table keeps a weak reference to the
47 // element; no need for explicit removal.
40 UpgradeCandidateMap::const_iterator::Keys end = m_upgradeCandidates.end().ke ys(); 48 UpgradeCandidateMap::const_iterator::Keys end = m_upgradeCandidates.end().ke ys();
41 for (UpgradeCandidateMap::const_iterator::Keys it = m_upgradeCandidates.begi n().keys(); it != end; ++it) 49 for (UpgradeCandidateMap::const_iterator::Keys it = m_upgradeCandidates.begi n().keys(); it != end; ++it)
42 unobserve(*it); 50 unobserve(*it);
haraken 2014/05/26 15:40:23 Just help me understand: As far as I see the code,
sof 2014/05/26 16:41:08 The weakly held Elements keep the CustomElementObs
haraken 2014/05/27 01:08:45 Correct me if I'm wrong:
sof 2014/05/27 05:29:51 It is triggered by the call to wasDestroyed() in ~
haraken 2014/05/27 05:47:30 Sorry, I was misreading the call path to CustomEle
sof 2014/05/27 11:59:14 That matches my understanding also. I've been comp
51 #endif
43 } 52 }
44 53
45 void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descri ptor, Element* element) 54 void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descri ptor, Element* element)
46 { 55 {
47 observe(element); 56 observe(element);
48 57
49 UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, des criptor); 58 UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, des criptor);
50 ASSERT_UNUSED(result, result.isNewEntry); 59 ASSERT_UNUSED(result, result.isNewEntry);
51 60
52 UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descript or); 61 UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descript or);
53 ElementSet* elements; 62 ElementSet* elements;
54 if (it == m_unresolvedDefinitions.end()) 63 if (it == m_unresolvedDefinitions.end())
55 elements = &m_unresolvedDefinitions.add(descriptor, ElementSet()).stored Value->value; 64 elements = m_unresolvedDefinitions.add(descriptor, adoptPtrWillBeNoop(ne w ElementSet())).storedValue->value;
56 else 65 else
57 elements = &it->value; 66 elements = it->value;
58 elements->add(element); 67 elements->add(element);
59 } 68 }
60 69
61 void CustomElementUpgradeCandidateMap::remove(Element* element) 70 void CustomElementUpgradeCandidateMap::remove(Element* element)
haraken 2014/05/26 15:40:23 Who calls this method? As far as I see the code se
sof 2014/05/26 16:41:08 You're quite right, unused. Nice, removed and simp
62 { 71 {
63 unobserve(element); 72 unobserve(element);
64 removeCommon(element); 73 removeCommon(element);
65 } 74 }
66 75
67 void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element) 76 void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element)
68 { 77 {
69 CustomElementObserver::elementWasDestroyed(element); 78 CustomElementObserver::elementWasDestroyed(element);
70 removeCommon(element); 79 removeCommon(element);
71 } 80 }
72 81
73 void CustomElementUpgradeCandidateMap::removeCommon(Element* element) 82 void CustomElementUpgradeCandidateMap::removeCommon(Element* element)
74 { 83 {
75 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); 84 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element);
76 ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end()); 85 ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end());
77 86
78 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca ndidate->value); 87 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca ndidate->value);
79 ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end()); 88 ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end());
80 elements->value.remove(element); 89 elements->value->remove(element);
81 m_upgradeCandidates.remove(candidate); 90 m_upgradeCandidates.remove(candidate);
haraken 2014/05/26 15:40:23 Can this be candidate->remove() ? We won't want to
sof 2014/05/26 16:41:08 Can't be - this is removing it from another table.
82 } 91 }
83 92
84 void CustomElementUpgradeCandidateMap::elementDidFinishParsingChildren(Element* element) 93 void CustomElementUpgradeCandidateMap::elementDidFinishParsingChildren(Element* element)
85 { 94 {
86 // An upgrade candidate finished parsing; reorder so that eventual 95 // An upgrade candidate finished parsing; reorder so that eventual
87 // upgrade order matches finished-parsing order. 96 // upgrade order matches finished-parsing order.
88 moveToEnd(element); 97 moveToEnd(element);
89 } 98 }
90 99
91 void CustomElementUpgradeCandidateMap::moveToEnd(Element* element) 100 void CustomElementUpgradeCandidateMap::moveToEnd(Element* element)
92 { 101 {
93 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); 102 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element);
94 ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end()); 103 ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end());
95 104
96 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca ndidate->value); 105 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca ndidate->value);
97 ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end()); 106 ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end());
98 elements->value.appendOrMoveToLast(element); 107 elements->value->appendOrMoveToLast(element);
99 } 108 }
100 109
101 ListHashSet<Element*> CustomElementUpgradeCandidateMap::takeUpgradeCandidatesFor (const CustomElementDescriptor& descriptor) 110 const CustomElementUpgradeCandidateMap::ElementSet* CustomElementUpgradeCandidat eMap::takeUpgradeCandidatesFor(const CustomElementDescriptor& descriptor)
102 { 111 {
103 const ListHashSet<Element*>& candidates = m_unresolvedDefinitions.take(descr iptor); 112 const ElementSet* candidates = m_unresolvedDefinitions.take(descriptor);
104 113
105 for (ElementSet::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate) { 114 if (!candidates)
115 return 0;
haraken 2014/05/26 15:40:23 Can this happen? If no, we might want to keep Elem
sof 2014/05/26 15:46:18 It will happen if you call registerElement() befor
haraken 2014/05/27 01:08:45 Just help me understand: Before this CL, we were u
sof 2014/05/27 11:59:14 hashSet.take()'s return type is HashTraits<ValueTy
116
117 for (ElementSet::const_iterator candidate = candidates->begin(); candidate ! = candidates->end(); ++candidate) {
106 unobserve(*candidate); 118 unobserve(*candidate);
107 m_upgradeCandidates.remove(*candidate); 119 m_upgradeCandidates.remove(*candidate);
108 } 120 }
109
110 return candidates; 121 return candidates;
111 } 122 }
112 123
124 void CustomElementUpgradeCandidateMap::trace(Visitor* visitor)
125 {
126 visitor->trace(m_upgradeCandidates);
127 visitor->trace(m_unresolvedDefinitions);
128 CustomElementObserver::trace(visitor);
113 } 129 }
130
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698