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

Side by Side Diff: Source/core/css/RuleFeature.cpp

Issue 149513011: Pass around CSSSelector by reference instead of pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « Source/core/css/RuleFeature.h ('k') | Source/core/css/RuleSet.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 19 matching lines...) Expand all
30 #include "core/css/RuleFeature.h" 30 #include "core/css/RuleFeature.h"
31 31
32 #include "HTMLNames.h" 32 #include "HTMLNames.h"
33 #include "RuntimeEnabledFeatures.h" 33 #include "RuntimeEnabledFeatures.h"
34 #include "core/css/CSSSelector.h" 34 #include "core/css/CSSSelector.h"
35 #include "core/css/CSSSelectorList.h" 35 #include "core/css/CSSSelectorList.h"
36 #include "core/css/RuleSet.h" 36 #include "core/css/RuleSet.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 static bool isSkippableComponentForInvalidation(const CSSSelector* selector) 40 static bool isSkippableComponentForInvalidation(const CSSSelector& selector)
41 { 41 {
42 if (selector->matchesPseudoElement() || selector->pseudoType() == CSSSelecto r::PseudoHost) 42 if (selector.matchesPseudoElement() || selector.pseudoType() == CSSSelector: :PseudoHost)
43 return false; 43 return false;
44 return true; 44 return true;
45 } 45 }
46 46
47 // This method is somewhat conservative in what it acceptss. 47 // This method is somewhat conservative in what it acceptss.
48 static bool supportsClassDescendantInvalidation(const CSSSelector* selector) 48 static bool supportsClassDescendantInvalidation(const CSSSelector& selector)
49 { 49 {
50 bool foundDescendantRelation = false; 50 bool foundDescendantRelation = false;
51 bool foundAncestorIdent = false; 51 bool foundAncestorIdent = false;
52 bool foundIdent = false; 52 bool foundIdent = false;
53 for (const CSSSelector* component = selector; component; component = compone nt->tagHistory()) { 53 for (const CSSSelector* component = &selector; component; component = compon ent->tagHistory()) {
54 54
55 // FIXME: We should allow pseudo elements, but we need to change how the y hook 55 // FIXME: We should allow pseudo elements, but we need to change how the y hook
56 // into recalcStyle by moving them to recalcOwnStyle instead of recalcCh ildStyle. 56 // into recalcStyle by moving them to recalcOwnStyle instead of recalcCh ildStyle.
57 57
58 if (component->m_match == CSSSelector::Tag 58 if (component->m_match == CSSSelector::Tag
59 || component->m_match == CSSSelector::Id 59 || component->m_match == CSSSelector::Id
60 || component->m_match == CSSSelector::Class) { 60 || component->m_match == CSSSelector::Class) {
61 if (!foundDescendantRelation) 61 if (!foundDescendantRelation)
62 foundIdent = true; 62 foundIdent = true;
63 else 63 else
64 foundAncestorIdent = true; 64 foundAncestorIdent = true;
65 } else if (!isSkippableComponentForInvalidation(component)) { 65 } else if (!isSkippableComponentForInvalidation(*component)) {
66 return false; 66 return false;
67 } 67 }
68 // FIXME: We can probably support ChildTree and DescendantTree. 68 // FIXME: We can probably support ChildTree and DescendantTree.
69 switch (component->relation()) { 69 switch (component->relation()) {
70 case CSSSelector::Descendant: 70 case CSSSelector::Descendant:
71 case CSSSelector::Child: 71 case CSSSelector::Child:
72 foundDescendantRelation = true; 72 foundDescendantRelation = true;
73 // Fall through! 73 // Fall through!
74 case CSSSelector::SubSelector: 74 case CSSSelector::SubSelector:
75 continue; 75 continue;
76 default: 76 default:
77 return false; 77 return false;
78 } 78 }
79 } 79 }
80 return foundDescendantRelation && foundAncestorIdent && foundIdent; 80 return foundDescendantRelation && foundAncestorIdent && foundIdent;
81 } 81 }
82 82
83 void extractClassIdOrTag(const CSSSelector& selector, HashSet<AtomicString>& cla sses, AtomicString& id, AtomicString& tagName) 83 void extractClassIdOrTag(const CSSSelector& selector, HashSet<AtomicString>& cla sses, AtomicString& id, AtomicString& tagName)
84 { 84 {
85 if (selector.m_match == CSSSelector::Tag) 85 if (selector.m_match == CSSSelector::Tag)
86 tagName = selector.tagQName().localName(); 86 tagName = selector.tagQName().localName();
87 else if (selector.m_match == CSSSelector::Id) 87 else if (selector.m_match == CSSSelector::Id)
88 id = selector.value(); 88 id = selector.value();
89 else if (selector.m_match == CSSSelector::Class) 89 else if (selector.m_match == CSSSelector::Class)
90 classes.add(selector.value()); 90 classes.add(selector.value());
91 } 91 }
92 92
93 bool RuleFeatureSet::updateClassInvalidationSets(const CSSSelector* selector) 93 bool RuleFeatureSet::updateClassInvalidationSets(const CSSSelector& selector)
94 { 94 {
95 if (!selector)
96 return false;
97 if (!supportsClassDescendantInvalidation(selector)) 95 if (!supportsClassDescendantInvalidation(selector))
98 return false; 96 return false;
99 97
100 HashSet<AtomicString> classes; 98 HashSet<AtomicString> classes;
101 AtomicString id; 99 AtomicString id;
102 AtomicString tagName; 100 AtomicString tagName;
103 101
104 const CSSSelector* lastSelector = selector; 102 const CSSSelector* lastSelector = &selector;
105 for (; lastSelector->relation() == CSSSelector::SubSelector; lastSelector = lastSelector->tagHistory()) { 103 for (; lastSelector->relation() == CSSSelector::SubSelector; lastSelector = lastSelector->tagHistory()) {
106 extractClassIdOrTag(*selector, classes, id, tagName); 104 extractClassIdOrTag(selector, classes, id, tagName);
107 } 105 }
108 extractClassIdOrTag(*selector, classes, id, tagName); 106 extractClassIdOrTag(selector, classes, id, tagName);
109 107
110 for ( ; selector; selector = selector->tagHistory()) { 108 for (const CSSSelector* current = &selector ; current; current = current->ta gHistory()) {
111 if (selector->m_match == CSSSelector::Class) { 109 if (current->m_match == CSSSelector::Class) {
112 DescendantInvalidationSet& invalidationSet = ensureClassInvalidation Set(selector->value()); 110 DescendantInvalidationSet& invalidationSet = ensureClassInvalidation Set(current->value());
113 if (!id.isEmpty()) 111 if (!id.isEmpty())
114 invalidationSet.addId(id); 112 invalidationSet.addId(id);
115 if (!tagName.isEmpty()) 113 if (!tagName.isEmpty())
116 invalidationSet.addTagName(tagName); 114 invalidationSet.addTagName(tagName);
117 for (HashSet<AtomicString>::const_iterator it = classes.begin(); it != classes.end(); ++it) { 115 for (HashSet<AtomicString>::const_iterator it = classes.begin(); it != classes.end(); ++it) {
118 invalidationSet.addClass(*it); 116 invalidationSet.addClass(*it);
119 } 117 }
120 } 118 }
121 } 119 }
122 return true; 120 return true;
(...skipping 27 matching lines...) Expand all
150 } 148 }
151 149
152 DescendantInvalidationSet& RuleFeatureSet::ensureClassInvalidationSet(const Atom icString& className) 150 DescendantInvalidationSet& RuleFeatureSet::ensureClassInvalidationSet(const Atom icString& className)
153 { 151 {
154 InvalidationSetMap::AddResult addResult = m_classInvalidationSets.add(classN ame, 0); 152 InvalidationSetMap::AddResult addResult = m_classInvalidationSets.add(classN ame, 0);
155 if (addResult.isNewEntry) 153 if (addResult.isNewEntry)
156 addResult.iterator->value = DescendantInvalidationSet::create(); 154 addResult.iterator->value = DescendantInvalidationSet::create();
157 return *addResult.iterator->value; 155 return *addResult.iterator->value;
158 } 156 }
159 157
160 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector) 158 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector)
161 { 159 {
162 collectFeaturesFromSelector(selector, m_metadata); 160 collectFeaturesFromSelector(selector, m_metadata);
163 } 161 }
164 162
165 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector, Ru leFeatureSet::FeatureMetadata& metadata) 163 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector, Ru leFeatureSet::FeatureMetadata& metadata)
166 { 164 {
167 for (; selector; selector = selector->tagHistory()) { 165 for (const CSSSelector* current = &selector; current; current = current->tag History()) {
168 if (selector->m_match == CSSSelector::Id) 166 if (current->m_match == CSSSelector::Id)
169 metadata.idsInRules.add(selector->value()); 167 metadata.idsInRules.add(current->value());
170 else if (selector->m_match == CSSSelector::Class) 168 else if (current->m_match == CSSSelector::Class)
171 metadata.classesInRules.add(selector->value()); 169 metadata.classesInRules.add(current->value());
172 else if (selector->isAttributeSelector()) 170 else if (current->isAttributeSelector())
173 metadata.attrsInRules.add(selector->attribute().localName()); 171 metadata.attrsInRules.add(current->attribute().localName());
174 172
175 if (selector->pseudoType() == CSSSelector::PseudoFirstLine) 173 if (current->pseudoType() == CSSSelector::PseudoFirstLine)
176 metadata.usesFirstLineRules = true; 174 metadata.usesFirstLineRules = true;
177 if (selector->isDirectAdjacentSelector()) 175 if (current->isDirectAdjacentSelector())
178 metadata.maxDirectAdjacentSelectors++; 176 metadata.maxDirectAdjacentSelectors++;
179 if (selector->isSiblingSelector()) 177 if (current->isSiblingSelector())
180 metadata.foundSiblingSelector = true; 178 metadata.foundSiblingSelector = true;
181 179
182 collectFeaturesFromSelectorList(selector->selectorList(), metadata); 180 collectFeaturesFromSelectorList(current->selectorList(), metadata);
183 } 181 }
184 } 182 }
185 183
186 void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* sele ctorList, RuleFeatureSet::FeatureMetadata& metadata) 184 void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* sele ctorList, RuleFeatureSet::FeatureMetadata& metadata)
187 { 185 {
188 if (!selectorList) 186 if (!selectorList)
189 return; 187 return;
190 188
191 for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(selector)) { 189 for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector)) {
192 for (const CSSSelector* subSelector = selector; subSelector; subSelector = subSelector->tagHistory()) 190 for (const CSSSelector* subSelector = selector; subSelector; subSelector = subSelector->tagHistory())
193 collectFeaturesFromSelector(subSelector, metadata); 191 collectFeaturesFromSelector(*subSelector, metadata);
194 } 192 }
195 } 193 }
196 194
197 void RuleFeatureSet::FeatureMetadata::add(const FeatureMetadata& other) 195 void RuleFeatureSet::FeatureMetadata::add(const FeatureMetadata& other)
198 { 196 {
199 usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules; 197 usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules;
200 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors); 198 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors);
201 199
202 HashSet<AtomicString>::const_iterator end = other.idsInRules.end(); 200 HashSet<AtomicString>::const_iterator end = other.idsInRules.end();
203 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it != end; ++it) 201 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it != end; ++it)
(...skipping 30 matching lines...) Expand all
234 } 232 }
235 233
236 void RuleFeatureSet::clear() 234 void RuleFeatureSet::clear()
237 { 235 {
238 m_metadata.clear(); 236 m_metadata.clear();
239 siblingRules.clear(); 237 siblingRules.clear();
240 uncommonAttributeRules.clear(); 238 uncommonAttributeRules.clear();
241 } 239 }
242 240
243 } // namespace WebCore 241 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/RuleFeature.h ('k') | Source/core/css/RuleSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698