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

Side by Side Diff: Source/core/css/RuleSet.h

Issue 17616009: RuleSet should use malloc rather than Vector (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make fancy Created 7 years, 6 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) 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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 * 19 *
20 */ 20 */
21 21
22 #ifndef RuleSet_h 22 #ifndef RuleSet_h
23 #define RuleSet_h 23 #define RuleSet_h
24 24
25 #include "core/css/RuleFeature.h" 25 #include "core/css/RuleFeature.h"
26 #include "core/css/StyleRule.h" 26 #include "core/css/StyleRule.h"
27 #include "wtf/Forward.h" 27 #include "wtf/Forward.h"
28 #include "wtf/HashMap.h" 28 #include "wtf/HashMap.h"
29 #include "wtf/LinkedStack.h" 29 #include "wtf/LinkedStack.h"
30 #include "wtf/OwnArrayPtr.h"
30 31
31 namespace WebCore { 32 namespace WebCore {
32 33
33 enum AddRuleFlags { 34 enum AddRuleFlags {
34 RuleHasNoSpecialState = 0, 35 RuleHasNoSpecialState = 0,
35 RuleHasDocumentSecurityOrigin = 1, 36 RuleHasDocumentSecurityOrigin = 1,
36 RuleCanUseFastCheckSelector = 1 << 1, 37 RuleCanUseFastCheckSelector = 1 << 1,
37 RuleIsInRegionRule = 1 << 2, 38 RuleIsInRegionRule = 1 << 2,
38 }; 39 };
39 40
40 enum PropertyWhitelistType { 41 enum PropertyWhitelistType {
41 PropertyWhitelistNone = 0, 42 PropertyWhitelistNone = 0,
42 PropertyWhitelistRegion, 43 PropertyWhitelistRegion,
43 PropertyWhitelistCue 44 PropertyWhitelistCue
44 }; 45 };
45 46
46 class CSSSelector; 47 class CSSSelector;
47 class ContainerNode; 48 class ContainerNode;
48 class MediaQueryEvaluator; 49 class MediaQueryEvaluator;
49 class StyleResolver; 50 class StyleResolver;
50 class StyleRuleRegion; 51 class StyleRuleRegion;
51 class StyleSheetContents; 52 class StyleSheetContents;
52 53
53 class RuleData { 54 class RuleData {
55 NEW_DELETE_SAME_AS_MALLOC_FREE;
54 public: 56 public:
55 RuleData(StyleRule*, unsigned selectorIndex, unsigned position, AddRuleFlags ); 57 RuleData(StyleRule*, unsigned selectorIndex, unsigned position, AddRuleFlags );
56 58
57 unsigned position() const { return m_position; } 59 unsigned position() const { return m_position; }
58 StyleRule* rule() const { return m_rule; } 60 StyleRule* rule() const { return m_rule; }
59 const CSSSelector* selector() const { return m_rule->selectorList().selector At(m_selectorIndex); } 61 const CSSSelector* selector() const { return m_rule->selectorList().selector At(m_selectorIndex); }
60 unsigned selectorIndex() const { return m_selectorIndex; } 62 unsigned selectorIndex() const { return m_selectorIndex; }
61 63
64 bool isLastInArray() const { return m_isLastInArray; }
65 void setLastInArray(bool flag) { m_isLastInArray = flag ? 1 : 0; }
esprehn 2013/06/26 00:37:33 I don't think you need the ternary in here.
abarth-chromium 2013/06/26 00:57:00 Done.
66
62 bool hasFastCheckableSelector() const { return m_hasFastCheckableSelector; } 67 bool hasFastCheckableSelector() const { return m_hasFastCheckableSelector; }
63 bool hasMultipartSelector() const { return m_hasMultipartSelector; } 68 bool hasMultipartSelector() const { return m_hasMultipartSelector; }
64 bool hasRightmostSelectorMatchingHTMLBasedOnRuleHash() const { return m_hasR ightmostSelectorMatchingHTMLBasedOnRuleHash; } 69 bool hasRightmostSelectorMatchingHTMLBasedOnRuleHash() const { return m_hasR ightmostSelectorMatchingHTMLBasedOnRuleHash; }
65 bool containsUncommonAttributeSelector() const { return m_containsUncommonAt tributeSelector; } 70 bool containsUncommonAttributeSelector() const { return m_containsUncommonAt tributeSelector; }
66 unsigned specificity() const { return m_specificity; } 71 unsigned specificity() const { return m_specificity; }
67 unsigned linkMatchType() const { return m_linkMatchType; } 72 unsigned linkMatchType() const { return m_linkMatchType; }
68 bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; } 73 bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; }
69 PropertyWhitelistType propertyWhitelistType(bool isMatchingUARules = false) const { return isMatchingUARules ? PropertyWhitelistNone : static_cast<PropertyW hitelistType>(m_propertyWhitelistType); } 74 PropertyWhitelistType propertyWhitelistType(bool isMatchingUARules = false) const { return isMatchingUARules ? PropertyWhitelistNone : static_cast<PropertyW hitelistType>(m_propertyWhitelistType); }
70 // Try to balance between memory usage (there can be lots of RuleData object s) and good filtering performance. 75 // Try to balance between memory usage (there can be lots of RuleData object s) and good filtering performance.
71 static const unsigned maximumIdentifierCount = 4; 76 static const unsigned maximumIdentifierCount = 4;
72 const unsigned* descendantSelectorIdentifierHashes() const { return m_descen dantSelectorIdentifierHashes; } 77 const unsigned* descendantSelectorIdentifierHashes() const { return m_descen dantSelectorIdentifierHashes; }
73 78
74 void reportMemoryUsage(MemoryObjectInfo*) const; 79 void reportMemoryUsage(MemoryObjectInfo*) const;
75 80
76 private: 81 private:
77 StyleRule* m_rule; 82 StyleRule* m_rule;
78 unsigned m_selectorIndex : 13; 83 unsigned m_selectorIndex : 12;
84 unsigned m_isLastInArray : 1; // We store an array of RuleData objects in a primitive array.
79 // This number was picked fairly arbitrarily. We can probably lower it if we need to. 85 // This number was picked fairly arbitrarily. We can probably lower it if we need to.
80 // Some simple testing showed <100,000 RuleData's on large sites. 86 // Some simple testing showed <100,000 RuleData's on large sites.
81 unsigned m_position : 18; 87 unsigned m_position : 18;
82 unsigned m_hasFastCheckableSelector : 1; 88 unsigned m_hasFastCheckableSelector : 1;
83 unsigned m_specificity : 24; 89 unsigned m_specificity : 24;
84 unsigned m_hasMultipartSelector : 1; 90 unsigned m_hasMultipartSelector : 1;
85 unsigned m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash : 1; 91 unsigned m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash : 1;
86 unsigned m_containsUncommonAttributeSelector : 1; 92 unsigned m_containsUncommonAttributeSelector : 1;
87 unsigned m_linkMatchType : 2; // SelectorChecker::LinkMatchMask 93 unsigned m_linkMatchType : 2; // SelectorChecker::LinkMatchMask
88 unsigned m_hasDocumentSecurityOrigin : 1; 94 unsigned m_hasDocumentSecurityOrigin : 1;
(...skipping 15 matching lines...) Expand all
104 WTF_MAKE_NONCOPYABLE(RuleSet); WTF_MAKE_FAST_ALLOCATED; 110 WTF_MAKE_NONCOPYABLE(RuleSet); WTF_MAKE_FAST_ALLOCATED;
105 public: 111 public:
106 static PassOwnPtr<RuleSet> create() { return adoptPtr(new RuleSet); } 112 static PassOwnPtr<RuleSet> create() { return adoptPtr(new RuleSet); }
107 113
108 void addRulesFromSheet(StyleSheetContents*, const MediaQueryEvaluator&, Styl eResolver* = 0, const ContainerNode* = 0); 114 void addRulesFromSheet(StyleSheetContents*, const MediaQueryEvaluator&, Styl eResolver* = 0, const ContainerNode* = 0);
109 void addStyleRule(StyleRule*, AddRuleFlags); 115 void addStyleRule(StyleRule*, AddRuleFlags);
110 void addRule(StyleRule*, unsigned selectorIndex, AddRuleFlags); 116 void addRule(StyleRule*, unsigned selectorIndex, AddRuleFlags);
111 117
112 const RuleFeatureSet& features() const { return m_features; } 118 const RuleFeatureSet& features() const { return m_features; }
113 119
114 const Vector<RuleData>* idRules(AtomicStringImpl* key) const { ASSERT(!m_pen dingRules); return m_idRules.get(key); } 120 const RuleData* idRules(AtomicStringImpl* key) const { ASSERT(!m_pendingRule s); return m_idRules.get(key); }
115 const Vector<RuleData>* classRules(AtomicStringImpl* key) const { ASSERT(!m_ pendingRules); return m_classRules.get(key); } 121 const RuleData* classRules(AtomicStringImpl* key) const { ASSERT(!m_pendingR ules); return m_classRules.get(key); }
116 const Vector<RuleData>* tagRules(AtomicStringImpl* key) const { ASSERT(!m_pe ndingRules); return m_tagRules.get(key); } 122 const RuleData* tagRules(AtomicStringImpl* key) const { ASSERT(!m_pendingRul es); return m_tagRules.get(key); }
117 const Vector<RuleData>* shadowPseudoElementRules(AtomicStringImpl* key) cons t { ASSERT(!m_pendingRules); return m_shadowPseudoElementRules.get(key); } 123 const RuleData* shadowPseudoElementRules(AtomicStringImpl* key) const { ASSE RT(!m_pendingRules); return m_shadowPseudoElementRules.get(key); }
esprehn 2013/06/26 00:37:33 We might consider a WTF class someday that does th
abarth-chromium 2013/06/26 00:57:00 Yeah.
118 const Vector<RuleData>* linkPseudoClassRules() const { ASSERT(!m_pendingRule s); return &m_linkPseudoClassRules; } 124 const Vector<RuleData>* linkPseudoClassRules() const { ASSERT(!m_pendingRule s); return &m_linkPseudoClassRules; }
119 const Vector<RuleData>* cuePseudoRules() const { ASSERT(!m_pendingRules); re turn &m_cuePseudoRules; } 125 const Vector<RuleData>* cuePseudoRules() const { ASSERT(!m_pendingRules); re turn &m_cuePseudoRules; }
120 const Vector<RuleData>* focusPseudoClassRules() const { ASSERT(!m_pendingRul es); return &m_focusPseudoClassRules; } 126 const Vector<RuleData>* focusPseudoClassRules() const { ASSERT(!m_pendingRul es); return &m_focusPseudoClassRules; }
121 const Vector<RuleData>* universalRules() const { ASSERT(!m_pendingRules); re turn &m_universalRules; } 127 const Vector<RuleData>* universalRules() const { ASSERT(!m_pendingRules); re turn &m_universalRules; }
122 const Vector<StyleRulePage*>& pageRules() const { ASSERT(!m_pendingRules); r eturn m_pageRules; } 128 const Vector<StyleRulePage*>& pageRules() const { ASSERT(!m_pendingRules); r eturn m_pageRules; }
123 129
124 unsigned ruleCount() const { return m_ruleCount; } 130 unsigned ruleCount() const { return m_ruleCount; }
125 131
126 void compactRulesIfNeeded() 132 void compactRulesIfNeeded()
127 { 133 {
(...skipping 10 matching lines...) Expand all
138 void reportMemoryUsage(MemoryObjectInfo*) const; 144 void reportMemoryUsage(MemoryObjectInfo*) const;
139 145
140 const CSSSelector* selector; 146 const CSSSelector* selector;
141 OwnPtr<RuleSet> ruleSet; 147 OwnPtr<RuleSet> ruleSet;
142 }; 148 };
143 149
144 Vector<RuleSetSelectorPair> m_regionSelectorsAndRuleSets; 150 Vector<RuleSetSelectorPair> m_regionSelectorsAndRuleSets;
145 151
146 private: 152 private:
147 typedef HashMap<AtomicStringImpl*, OwnPtr<LinkedStack<RuleData> > > PendingR uleMap; 153 typedef HashMap<AtomicStringImpl*, OwnPtr<LinkedStack<RuleData> > > PendingR uleMap;
148 typedef HashMap<AtomicStringImpl*, OwnPtr<Vector<RuleData> > > CompactRuleMa p; 154 typedef HashMap<AtomicStringImpl*, OwnPtr<RuleData> > CompactRuleMap;
149 155
150 RuleSet() 156 RuleSet()
151 : m_ruleCount(0) 157 : m_ruleCount(0)
152 { 158 {
153 } 159 }
154 160
155 void addToRuleSet(AtomicStringImpl* key, PendingRuleMap&, const RuleData&); 161 void addToRuleSet(AtomicStringImpl* key, PendingRuleMap&, const RuleData&);
156 void addPageRule(StyleRulePage*); 162 void addPageRule(StyleRulePage*);
157 void addRegionRule(StyleRuleRegion*, bool hasDocumentSecurityOrigin); 163 void addRegionRule(StyleRuleRegion*, bool hasDocumentSecurityOrigin);
158 164
(...skipping 28 matching lines...) Expand all
187 RuleFeatureSet m_features; 193 RuleFeatureSet m_features;
188 Vector<StyleRulePage*> m_pageRules; 194 Vector<StyleRulePage*> m_pageRules;
189 195
190 unsigned m_ruleCount; 196 unsigned m_ruleCount;
191 OwnPtr<PendingRuleMaps> m_pendingRules; 197 OwnPtr<PendingRuleMaps> m_pendingRules;
192 }; 198 };
193 199
194 } // namespace WebCore 200 } // namespace WebCore
195 201
196 #endif // RuleSet_h 202 #endif // RuleSet_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698