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

Side by Side Diff: Source/core/dom/ElementData.h

Issue 273843003: [Oilpan]: Make StylePropertySet fully garbage collected. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix mac build 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 | Annotate | Revision Log
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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 #ifndef ElementData_h 31 #ifndef ElementData_h
32 #define ElementData_h 32 #define ElementData_h
33 33
34 #include "core/dom/Attribute.h" 34 #include "core/dom/Attribute.h"
35 #include "core/dom/SpaceSplitString.h" 35 #include "core/dom/SpaceSplitString.h"
36 #include "platform/heap/Handle.h"
36 #include "wtf/text/AtomicString.h" 37 #include "wtf/text/AtomicString.h"
37 38
38 namespace WebCore { 39 namespace WebCore {
39 40
40 class Attr; 41 class Attr;
41 class ShareableElementData; 42 class ShareableElementData;
42 class StylePropertySet; 43 class StylePropertySet;
43 class UniqueElementData; 44 class UniqueElementData;
44 45
45 // ElementData represents very common, but not necessarily unique to an element, 46 // ElementData represents very common, but not necessarily unique to an element,
46 // data such as attributes, inline style, and parsed class names and ids. 47 // data such as attributes, inline style, and parsed class names and ids.
47 class ElementData : public RefCounted<ElementData> { 48 class ElementData : public RefCountedWillBeGarbageCollectedFinalized<ElementData > {
48 WTF_MAKE_FAST_ALLOCATED; 49 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
49 public: 50 public:
51 #if ENABLE(OILPAN)
52 // Override GarbageCollectedFinalized's finalizeGarbageCollectedObject to
53 // dispatch to the correct subclass' destructor.
54 void finalizeGarbageCollectedObject();
55 #else
50 // Override RefCounted's deref() to ensure operator delete is called on 56 // Override RefCounted's deref() to ensure operator delete is called on
51 // the appropriate subclass type. 57 // the appropriate subclass type.
52 void deref(); 58 void deref();
59 #endif
53 60
54 void clearClass() const { m_classNames.clear(); } 61 void clearClass() const { m_classNames.clear(); }
55 void setClass(const AtomicString& className, bool shouldFoldCase) const { m_ classNames.set(className, shouldFoldCase); } 62 void setClass(const AtomicString& className, bool shouldFoldCase) const { m_ classNames.set(className, shouldFoldCase); }
56 const SpaceSplitString& classNames() const { return m_classNames; } 63 const SpaceSplitString& classNames() const { return m_classNames; }
57 64
58 const AtomicString& idForStyleResolution() const { return m_idForStyleResolu tion; } 65 const AtomicString& idForStyleResolution() const { return m_idForStyleResolu tion; }
59 void setIdForStyleResolution(const AtomicString& newId) const { m_idForStyle Resolution = newId; } 66 void setIdForStyleResolution(const AtomicString& newId) const { m_idForStyle Resolution = newId; }
60 67
61 const StylePropertySet* inlineStyle() const { return m_inlineStyle.get(); } 68 const StylePropertySet* inlineStyle() const { return m_inlineStyle.get(); }
62 69
63 const StylePropertySet* presentationAttributeStyle() const; 70 const StylePropertySet* presentationAttributeStyle() const;
64 71
65 // This is not a trivial getter and its return value should be cached for pe rformance. 72 // This is not a trivial getter and its return value should be cached for pe rformance.
66 size_t length() const; 73 size_t length() const;
67 bool isEmpty() const { return !length(); } 74 bool isEmpty() const { return !length(); }
68 75
69 const Attribute& attributeItem(unsigned index) const; 76 const Attribute& attributeItem(unsigned index) const;
70 const Attribute* getAttributeItem(const QualifiedName&) const; 77 const Attribute* getAttributeItem(const QualifiedName&) const;
71 size_t getAttributeItemIndex(const QualifiedName&, bool shouldIgnoreCase = f alse) const; 78 size_t getAttributeItemIndex(const QualifiedName&, bool shouldIgnoreCase = f alse) const;
72 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttr ibuteCase) const; 79 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttr ibuteCase) const;
73 size_t getAttrIndex(Attr*) const; 80 size_t getAttrIndex(Attr*) const;
74 81
75 bool hasID() const { return !m_idForStyleResolution.isNull(); } 82 bool hasID() const { return !m_idForStyleResolution.isNull(); }
76 bool hasClass() const { return !m_classNames.isNull(); } 83 bool hasClass() const { return !m_classNames.isNull(); }
77 84
78 bool isEquivalent(const ElementData* other) const; 85 bool isEquivalent(const ElementData* other) const;
79 86
80 bool isUnique() const { return m_isUnique; } 87 bool isUnique() const { return m_isUnique; }
81 88
89 void traceAfterDispatch(Visitor*);
90 void trace(Visitor*);
91
82 protected: 92 protected:
83 ElementData(); 93 ElementData();
84 explicit ElementData(unsigned arraySize); 94 explicit ElementData(unsigned arraySize);
85 ElementData(const ElementData&, bool isUnique); 95 ElementData(const ElementData&, bool isUnique);
86 96
87 // Keep the type in a bitfield instead of using virtual destructors to avoid adding a vtable. 97 // Keep the type in a bitfield instead of using virtual destructors to avoid adding a vtable.
88 unsigned m_isUnique : 1; 98 unsigned m_isUnique : 1;
89 unsigned m_arraySize : 28; 99 unsigned m_arraySize : 28;
90 mutable unsigned m_presentationAttributeStyleIsDirty : 1; 100 mutable unsigned m_presentationAttributeStyleIsDirty : 1;
91 mutable unsigned m_styleAttributeIsDirty : 1; 101 mutable unsigned m_styleAttributeIsDirty : 1;
92 mutable unsigned m_animatedSVGAttributesAreDirty : 1; 102 mutable unsigned m_animatedSVGAttributesAreDirty : 1;
93 103
94 mutable RefPtr<StylePropertySet> m_inlineStyle; 104 mutable RefPtrWillBeMember<StylePropertySet> m_inlineStyle;
95 mutable SpaceSplitString m_classNames; 105 mutable SpaceSplitString m_classNames;
96 mutable AtomicString m_idForStyleResolution; 106 mutable AtomicString m_idForStyleResolution;
97 107
98 private: 108 private:
99 friend class Element; 109 friend class Element;
100 friend class ShareableElementData; 110 friend class ShareableElementData;
101 friend class UniqueElementData; 111 friend class UniqueElementData;
102 friend class SVGElement; 112 friend class SVGElement;
103 113
114 #if !ENABLE(OILPAN)
104 void destroy(); 115 void destroy();
116 #endif
105 117
106 const Attribute* attributeBase() const; 118 const Attribute* attributeBase() const;
107 const Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnor eAttributeCase) const; 119 const Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnor eAttributeCase) const;
108 size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIg noreAttributeCase) const; 120 size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIg noreAttributeCase) const;
109 121
110 PassRefPtr<UniqueElementData> makeUniqueCopy() const; 122 PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const;
111 }; 123 };
112 124
113 #if COMPILER(MSVC) 125 #if COMPILER(MSVC)
114 #pragma warning(push) 126 #pragma warning(push)
115 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war ning 127 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war ning
116 #endif 128 #endif
117 129
118 // SharableElementData is managed by ElementDataCache and is produced by 130 // SharableElementData is managed by ElementDataCache and is produced by
119 // the parser during page load for elements that have identical attributes. This 131 // the parser during page load for elements that have identical attributes. This
120 // is a memory optimization since it's very common for many elements to have 132 // is a memory optimization since it's very common for many elements to have
121 // duplicate sets of attributes (ex. the same classes). 133 // duplicate sets of attributes (ex. the same classes).
122 class ShareableElementData FINAL : public ElementData { 134 class ShareableElementData FINAL : public ElementData {
123 public: 135 public:
124 static PassRefPtr<ShareableElementData> createWithAttributes(const Vector<At tribute>&); 136 static PassRefPtrWillBeRawPtr<ShareableElementData> createWithAttributes(con st Vector<Attribute>&);
125 137
126 explicit ShareableElementData(const Vector<Attribute>&); 138 explicit ShareableElementData(const Vector<Attribute>&);
127 explicit ShareableElementData(const UniqueElementData&); 139 explicit ShareableElementData(const UniqueElementData&);
128 ~ShareableElementData(); 140 ~ShareableElementData();
129 141
142 void traceAfterDispatch(Visitor* visitor) { ElementData::traceAfterDispatch( visitor); }
143
144 void* operator new(std::size_t, void* location)
esprehn 2014/05/14 20:25:27 Why is this needed? Can you add a comment?
wibling-chromium 2014/05/15 13:15:18 Sure. I will add a comment. This is needed because
145 {
146 return location;
147 }
148
130 Attribute m_attributeArray[0]; 149 Attribute m_attributeArray[0];
131 }; 150 };
132 151
133 #if COMPILER(MSVC) 152 #if COMPILER(MSVC)
134 #pragma warning(pop) 153 #pragma warning(pop)
135 #endif 154 #endif
136 155
137 // UniqueElementData is created when an element needs to mutate its attributes 156 // UniqueElementData is created when an element needs to mutate its attributes
138 // or gains presentation attribute style (ex. width="10"). It does not need to 157 // or gains presentation attribute style (ex. width="10"). It does not need to
139 // be created to fill in values in the ElementData that are derived from 158 // be created to fill in values in the ElementData that are derived from
140 // attributes. For example populating the m_inlineStyle from the style attribute 159 // attributes. For example populating the m_inlineStyle from the style attribute
141 // doesn't require a UniqueElementData as all elements with the same style 160 // doesn't require a UniqueElementData as all elements with the same style
142 // attribute will have the same inline style. 161 // attribute will have the same inline style.
143 class UniqueElementData FINAL : public ElementData { 162 class UniqueElementData FINAL : public ElementData {
144 public: 163 public:
145 static PassRefPtr<UniqueElementData> create(); 164 static PassRefPtrWillBeRawPtr<UniqueElementData> create();
146 PassRefPtr<ShareableElementData> makeShareableCopy() const; 165 PassRefPtrWillBeRawPtr<ShareableElementData> makeShareableCopy() const;
147 166
148 // These functions do no error/duplicate checking. 167 // These functions do no error/duplicate checking.
149 void addAttribute(const QualifiedName&, const AtomicString&); 168 void addAttribute(const QualifiedName&, const AtomicString&);
150 void removeAttribute(size_t index); 169 void removeAttribute(size_t index);
151 170
152 Attribute& attributeItem(unsigned index); 171 Attribute& attributeItem(unsigned index);
153 Attribute* getAttributeItem(const QualifiedName&); 172 Attribute* getAttributeItem(const QualifiedName&);
154 173
155 UniqueElementData(); 174 UniqueElementData();
156 explicit UniqueElementData(const ShareableElementData&); 175 explicit UniqueElementData(const ShareableElementData&);
157 explicit UniqueElementData(const UniqueElementData&); 176 explicit UniqueElementData(const UniqueElementData&);
158 177
178 void traceAfterDispatch(Visitor*);
179
159 // FIXME: We might want to support sharing element data for elements with 180 // FIXME: We might want to support sharing element data for elements with
160 // presentation attribute style. Lots of table cells likely have the same 181 // presentation attribute style. Lots of table cells likely have the same
161 // attributes. Most modern pages don't use presentation attributes though 182 // attributes. Most modern pages don't use presentation attributes though
162 // so this might not make sense. 183 // so this might not make sense.
163 mutable RefPtr<StylePropertySet> m_presentationAttributeStyle; 184 mutable RefPtrWillBeMember<StylePropertySet> m_presentationAttributeStyle;
164 Vector<Attribute, 4> m_attributeVector; 185 Vector<Attribute, 4> m_attributeVector;
165 }; 186 };
166 187
188 #if !ENABLE(OILPAN)
167 inline void ElementData::deref() 189 inline void ElementData::deref()
168 { 190 {
169 if (!derefBase()) 191 if (!derefBase())
170 return; 192 return;
171 destroy(); 193 destroy();
172 } 194 }
195 #endif
173 196
174 inline size_t ElementData::length() const 197 inline size_t ElementData::length() const
175 { 198 {
176 if (isUnique()) 199 if (isUnique())
177 return static_cast<const UniqueElementData*>(this)->m_attributeVector.si ze(); 200 return static_cast<const UniqueElementData*>(this)->m_attributeVector.si ze();
178 return m_arraySize; 201 return m_arraySize;
179 } 202 }
180 203
181 inline const StylePropertySet* ElementData::presentationAttributeStyle() const 204 inline const StylePropertySet* ElementData::presentationAttributeStyle() const
182 { 205 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 293 }
271 294
272 inline Attribute& UniqueElementData::attributeItem(unsigned index) 295 inline Attribute& UniqueElementData::attributeItem(unsigned index)
273 { 296 {
274 return m_attributeVector.at(index); 297 return m_attributeVector.at(index);
275 } 298 }
276 299
277 } // namespace WebCore 300 } // namespace WebCore
278 301
279 #endif // ElementData_h 302 #endif // ElementData_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698