OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 107 |
108 struct SameSizeAsRuleData { | 108 struct SameSizeAsRuleData { |
109 void* a; | 109 void* a; |
110 unsigned b; | 110 unsigned b; |
111 unsigned c; | 111 unsigned c; |
112 unsigned d[4]; | 112 unsigned d[4]; |
113 }; | 113 }; |
114 | 114 |
115 COMPILE_ASSERT(sizeof(RuleData) == sizeof(SameSizeAsRuleData), RuleData_should_s tay_small); | 115 COMPILE_ASSERT(sizeof(RuleData) == sizeof(SameSizeAsRuleData), RuleData_should_s tay_small); |
116 | 116 |
117 template<typename T> | |
118 class TerminatedArray { | |
abarth-chromium
2014/03/04 19:03:35
Can you move this into it's own header in WTF?
Erik Corry
2014/03/05 11:43:52
I think this is rather too hacky to move to WTF.
Vyacheslav Egorov (Chromium)
2014/03/05 12:44:07
I decided to move both TerminatedArray and Termina
| |
119 WTF_MAKE_FAST_ALLOCATED; | |
haraken
2014/03/05 01:47:06
Add WTF_MAKE_NONCOPYABLE(TerminatedArray).
Vyacheslav Egorov (Chromium)
2014/03/05 12:44:07
Done.
| |
120 public: | |
121 static PassOwnPtr<TerminatedArray> create(size_t capacity) | |
122 { | |
123 return adoptPtr(static_cast<TerminatedArray*>(fastMalloc(capacity * size of(T)))); | |
Erik Corry
2014/03/05 11:43:52
Consider using zeroed malloc here, since normally
Vyacheslav Egorov (Chromium)
2014/03/05 12:44:07
I will all be filled with real objects, so zeroing
| |
124 } | |
125 | |
126 PassOwnPtr<TerminatedArray> realloc(size_t capacity) | |
haraken
2014/03/05 01:47:06
realloc => resize ?
Vyacheslav Egorov (Chromium)
2014/03/05 12:44:07
Done.
| |
127 { | |
128 return adoptPtr(static_cast<TerminatedArray*>(fastRealloc(this, capacity * sizeof(T)))); | |
129 } | |
130 | |
131 T& at(size_t idx) { return reinterpret_cast<T*>(this)[idx]; } | |
abarth-chromium
2014/03/04 19:03:35
idx -> index
Vyacheslav Egorov (Chromium)
2014/03/05 12:44:07
Done.
| |
132 const T& at(size_t idx) const { return reinterpret_cast<const T*>(this)[idx] ; } | |
haraken
2014/03/05 01:47:06
Shall we add operator[] ?
Vyacheslav Egorov (Chromium)
2014/03/05 12:44:07
It will be useless because we pass these arrays by
| |
133 | |
134 template<typename U> | |
135 class iterator_base { | |
136 public: | |
137 iterator_base& operator++() | |
138 { | |
139 if (m_val->isLastInArray()) { | |
140 m_val = 0; | |
141 } else { | |
142 ++m_val; | |
143 } | |
144 return *this; | |
145 } | |
146 | |
147 U& operator*() const { return *m_val; } | |
148 | |
149 bool operator!=(const iterator_base& other) { return m_val != other.m_va l; } | |
haraken
2014/03/05 01:47:06
Shall we add operator== ?
Vyacheslav Egorov (Chromium)
2014/03/05 12:44:07
Done.
| |
150 | |
151 private: | |
152 iterator_base(U* val) : m_val(val) { } | |
153 | |
154 U* m_val; | |
155 | |
156 friend class TerminatedArray; | |
157 }; | |
158 | |
159 typedef iterator_base<T> iterator; | |
160 typedef iterator_base<const T> const_iterator; | |
161 | |
162 iterator begin() { return iterator(reinterpret_cast<T*>(this)); } | |
163 const_iterator begin() const { return const_iterator(reinterpret_cast<const T*>(this)); } | |
164 | |
165 iterator end() { return iterator(0); } | |
166 const_iterator end() const { return const_iterator(0); } | |
167 | |
168 size_t size() const | |
wibling-chromium
2014/03/05 09:28:32
Consider adding a comment describing how this data
Vyacheslav Egorov (Chromium)
2014/03/05 12:44:07
Done.
| |
169 { | |
170 size_t count = 0; | |
171 for (const_iterator it = begin(); it != end(); ++it) | |
172 count++; | |
173 return count; | |
174 } | |
175 }; | |
176 | |
117 class RuleSet { | 177 class RuleSet { |
118 WTF_MAKE_NONCOPYABLE(RuleSet); WTF_MAKE_FAST_ALLOCATED; | 178 WTF_MAKE_NONCOPYABLE(RuleSet); WTF_MAKE_FAST_ALLOCATED; |
119 public: | 179 public: |
120 static PassOwnPtr<RuleSet> create() { return adoptPtr(new RuleSet); } | 180 static PassOwnPtr<RuleSet> create() { return adoptPtr(new RuleSet); } |
121 | 181 |
122 void addRulesFromSheet(StyleSheetContents*, const MediaQueryEvaluator&, AddR uleFlags = RuleHasNoSpecialState); | 182 void addRulesFromSheet(StyleSheetContents*, const MediaQueryEvaluator&, AddR uleFlags = RuleHasNoSpecialState); |
123 void addStyleRule(StyleRule*, AddRuleFlags); | 183 void addStyleRule(StyleRule*, AddRuleFlags); |
124 void addRule(StyleRule*, unsigned selectorIndex, AddRuleFlags); | 184 void addRule(StyleRule*, unsigned selectorIndex, AddRuleFlags); |
125 | 185 |
126 const RuleFeatureSet& features() const { return m_features; } | 186 const RuleFeatureSet& features() const { return m_features; } |
127 | 187 |
128 const RuleData* idRules(const AtomicString& key) const { ASSERT(!m_pendingRu les); return m_idRules.get(key); } | 188 const TerminatedArray<RuleData>* idRules(const AtomicString& key) const { AS SERT(!m_pendingRules); return m_idRules.get(key); } |
129 const RuleData* classRules(const AtomicString& key) const { ASSERT(!m_pendin gRules); return m_classRules.get(key); } | 189 const TerminatedArray<RuleData>* classRules(const AtomicString& key) const { ASSERT(!m_pendingRules); return m_classRules.get(key); } |
130 const RuleData* tagRules(const AtomicString& key) const { ASSERT(!m_pendingR ules); return m_tagRules.get(key); } | 190 const TerminatedArray<RuleData>* tagRules(const AtomicString& key) const { A SSERT(!m_pendingRules); return m_tagRules.get(key); } |
131 const RuleData* shadowPseudoElementRules(const AtomicString& key) const { AS SERT(!m_pendingRules); return m_shadowPseudoElementRules.get(key); } | 191 const TerminatedArray<RuleData>* shadowPseudoElementRules(const AtomicString & key) const { ASSERT(!m_pendingRules); return m_shadowPseudoElementRules.get(ke y); } |
132 const Vector<RuleData>* linkPseudoClassRules() const { ASSERT(!m_pendingRule s); return &m_linkPseudoClassRules; } | 192 const Vector<RuleData>* linkPseudoClassRules() const { ASSERT(!m_pendingRule s); return &m_linkPseudoClassRules; } |
133 const Vector<RuleData>* cuePseudoRules() const { ASSERT(!m_pendingRules); re turn &m_cuePseudoRules; } | 193 const Vector<RuleData>* cuePseudoRules() const { ASSERT(!m_pendingRules); re turn &m_cuePseudoRules; } |
134 const Vector<RuleData>* focusPseudoClassRules() const { ASSERT(!m_pendingRul es); return &m_focusPseudoClassRules; } | 194 const Vector<RuleData>* focusPseudoClassRules() const { ASSERT(!m_pendingRul es); return &m_focusPseudoClassRules; } |
135 const Vector<RuleData>* universalRules() const { ASSERT(!m_pendingRules); re turn &m_universalRules; } | 195 const Vector<RuleData>* universalRules() const { ASSERT(!m_pendingRules); re turn &m_universalRules; } |
136 const WillBeHeapVector<RawPtrWillBeMember<StyleRulePage> >& pageRules() cons t { ASSERT(!m_pendingRules); return m_pageRules; } | 196 const WillBeHeapVector<RawPtrWillBeMember<StyleRulePage> >& pageRules() cons t { ASSERT(!m_pendingRules); return m_pageRules; } |
137 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleViewport> >& viewportRule s() const { ASSERT(!m_pendingRules); return m_viewportRules; } | 197 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleViewport> >& viewportRule s() const { ASSERT(!m_pendingRules); return m_viewportRules; } |
138 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> >& fontFaceRule s() const { return m_fontFaceRules; } | 198 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> >& fontFaceRule s() const { return m_fontFaceRules; } |
139 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> >& keyframesRu les() const { return m_keyframesRules; } | 199 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> >& keyframesRu les() const { return m_keyframesRules; } |
140 const Vector<MinimalRuleData>& treeBoundaryCrossingRules() const { return m_ treeBoundaryCrossingRules; } | 200 const Vector<MinimalRuleData>& treeBoundaryCrossingRules() const { return m_ treeBoundaryCrossingRules; } |
141 const Vector<MinimalRuleData>& shadowDistributedRules() const { return m_sha dowDistributedRules; } | 201 const Vector<MinimalRuleData>& shadowDistributedRules() const { return m_sha dowDistributedRules; } |
(...skipping 15 matching lines...) Expand all Loading... | |
157 struct RuleSetSelectorPair { | 217 struct RuleSetSelectorPair { |
158 RuleSetSelectorPair(const CSSSelector* selector, PassOwnPtr<RuleSet> rul eSet) : selector(selector), ruleSet(ruleSet) { } | 218 RuleSetSelectorPair(const CSSSelector* selector, PassOwnPtr<RuleSet> rul eSet) : selector(selector), ruleSet(ruleSet) { } |
159 RuleSetSelectorPair(const RuleSetSelectorPair& rs) : selector(rs.selecto r), ruleSet(const_cast<RuleSetSelectorPair*>(&rs)->ruleSet.release()) { } | 219 RuleSetSelectorPair(const RuleSetSelectorPair& rs) : selector(rs.selecto r), ruleSet(const_cast<RuleSetSelectorPair*>(&rs)->ruleSet.release()) { } |
160 | 220 |
161 const CSSSelector* selector; | 221 const CSSSelector* selector; |
162 OwnPtr<RuleSet> ruleSet; | 222 OwnPtr<RuleSet> ruleSet; |
163 }; | 223 }; |
164 | 224 |
165 private: | 225 private: |
166 typedef HashMap<AtomicString, OwnPtr<LinkedStack<RuleData> > > PendingRuleMa p; | 226 typedef HashMap<AtomicString, OwnPtr<LinkedStack<RuleData> > > PendingRuleMa p; |
167 typedef HashMap<AtomicString, OwnPtr<RuleData> > CompactRuleMap; | 227 typedef HashMap<AtomicString, OwnPtr<TerminatedArray<RuleData> > > CompactRu leMap; |
168 | 228 |
169 RuleSet() | 229 RuleSet() |
170 : m_ruleCount(0) | 230 : m_ruleCount(0) |
171 { | 231 { |
172 } | 232 } |
173 | 233 |
174 void addToRuleSet(const AtomicString& key, PendingRuleMap&, const RuleData&) ; | 234 void addToRuleSet(const AtomicString& key, PendingRuleMap&, const RuleData&) ; |
175 void addPageRule(StyleRulePage*); | 235 void addPageRule(StyleRulePage*); |
176 void addViewportRule(StyleRuleViewport*); | 236 void addViewportRule(StyleRuleViewport*); |
177 void addFontFaceRule(StyleRuleFontFace*); | 237 void addFontFaceRule(StyleRuleFontFace*); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 OwnPtr<PendingRuleMaps> m_pendingRules; | 279 OwnPtr<PendingRuleMaps> m_pendingRules; |
220 | 280 |
221 #ifndef NDEBUG | 281 #ifndef NDEBUG |
222 Vector<RuleData> m_allRules; | 282 Vector<RuleData> m_allRules; |
223 #endif | 283 #endif |
224 }; | 284 }; |
225 | 285 |
226 } // namespace WebCore | 286 } // namespace WebCore |
227 | 287 |
228 #endif // RuleSet_h | 288 #endif // RuleSet_h |
OLD | NEW |