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

Unified Diff: Source/core/css/SelectorCheckerFastPath.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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/SelectorCheckerFastPath.h ('k') | Source/core/css/SelectorFilter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/SelectorCheckerFastPath.cpp
diff --git a/Source/core/css/SelectorCheckerFastPath.cpp b/Source/core/css/SelectorCheckerFastPath.cpp
index 557f0438a56dc618b8a51d282558e5063d64c543..943e26239b8220073b34362346f833ce43870cc9 100644
--- a/Source/core/css/SelectorCheckerFastPath.cpp
+++ b/Source/core/css/SelectorCheckerFastPath.cpp
@@ -39,11 +39,11 @@ using namespace HTMLNames;
namespace {
-template <bool checkValue(const Element&, const CSSSelector*)>
+template <bool checkValue(const Element&, const CSSSelector&)>
inline bool fastCheckSingleSelector(const CSSSelector*& selector, const Element*& element, const CSSSelector*& topChildOrSubselector, const Element*& topChildOrSubselectorMatchElement)
{
for (; element; element = element->parentElement()) {
- if (checkValue(*element, selector)) {
+ if (checkValue(*element, *selector)) {
if (selector->relation() == CSSSelector::Descendant)
topChildOrSubselector = 0;
else if (!topChildOrSubselector) {
@@ -73,29 +73,29 @@ inline bool fastCheckSingleSelector(const CSSSelector*& selector, const Element*
return false;
}
-inline bool checkClassValue(const Element& element, const CSSSelector* selector)
+inline bool checkClassValue(const Element& element, const CSSSelector& selector)
{
- return element.hasClass() && element.classNames().contains(selector->value());
+ return element.hasClass() && element.classNames().contains(selector.value());
}
-inline bool checkIDValue(const Element& element, const CSSSelector* selector)
+inline bool checkIDValue(const Element& element, const CSSSelector& selector)
{
- return element.hasID() && element.idForStyleResolution() == selector->value();
+ return element.hasID() && element.idForStyleResolution() == selector.value();
}
-inline bool checkExactAttributeValue(const Element& element, const CSSSelector* selector)
+inline bool checkExactAttributeValue(const Element& element, const CSSSelector& selector)
{
- return SelectorChecker::checkExactAttribute(element, selector->attribute(), selector->value().impl());
+ return SelectorChecker::checkExactAttribute(element, selector.attribute(), selector.value().impl());
}
-inline bool checkTagValue(const Element& element, const CSSSelector* selector)
+inline bool checkTagValue(const Element& element, const CSSSelector& selector)
{
- return SelectorChecker::tagMatches(element, selector->tagQName());
+ return SelectorChecker::tagMatches(element, selector.tagQName());
}
}
-SelectorCheckerFastPath::SelectorCheckerFastPath(const CSSSelector* selector, const Element& element)
+SelectorCheckerFastPath::SelectorCheckerFastPath(const CSSSelector& selector, const Element& element)
: m_selector(selector)
, m_element(element)
{
@@ -105,7 +105,7 @@ bool SelectorCheckerFastPath::matchesRightmostSelector(SelectorChecker::VisitedM
{
ASSERT(SelectorCheckerFastPath::canUse(m_selector));
- switch (m_selector->m_match) {
+ switch (m_selector.m_match) {
case CSSSelector::Tag:
return checkTagValue(m_element, m_selector);
case CSSSelector::Class:
@@ -126,7 +126,7 @@ bool SelectorCheckerFastPath::matchesRightmostSelector(SelectorChecker::VisitedM
bool SelectorCheckerFastPath::matches() const
{
ASSERT(matchesRightmostSelector(SelectorChecker::VisitedMatchEnabled));
- const CSSSelector* selector = m_selector;
+ const CSSSelector* selector = &m_selector;
const Element* element = &m_element;
const CSSSelector* topChildOrSubselector = 0;
@@ -171,33 +171,33 @@ static inline bool isFastCheckableRelation(CSSSelector::Relation relation)
return relation == CSSSelector::Descendant || relation == CSSSelector::Child || relation == CSSSelector::SubSelector;
}
-static inline bool isFastCheckableMatch(const CSSSelector* selector)
+static inline bool isFastCheckableMatch(const CSSSelector& selector)
{
- if (selector->m_match == CSSSelector::Set) {
+ if (selector.m_match == CSSSelector::Set) {
// Style attribute is generated lazily but the fast path doesn't trigger it.
// Disallow them here rather than making the fast path more branchy.
- return selector->attribute() != styleAttr;
+ return selector.attribute() != styleAttr;
}
- if (selector->m_match == CSSSelector::Exact)
- return selector->attribute() != styleAttr && HTMLDocument::isCaseSensitiveAttribute(selector->attribute());
- return selector->m_match == CSSSelector::Tag || selector->m_match == CSSSelector::Id || selector->m_match == CSSSelector::Class;
+ if (selector.m_match == CSSSelector::Exact)
+ return selector.attribute() != styleAttr && HTMLDocument::isCaseSensitiveAttribute(selector.attribute());
+ return selector.m_match == CSSSelector::Tag || selector.m_match == CSSSelector::Id || selector.m_match == CSSSelector::Class;
}
-static inline bool isFastCheckableRightmostSelector(const CSSSelector* selector)
+static inline bool isFastCheckableRightmostSelector(const CSSSelector& selector)
{
- if (!isFastCheckableRelation(selector->relation()))
+ if (!isFastCheckableRelation(selector.relation()))
return false;
return isFastCheckableMatch(selector) || SelectorChecker::isCommonPseudoClassSelector(selector);
}
-bool SelectorCheckerFastPath::canUse(const CSSSelector* selector)
+bool SelectorCheckerFastPath::canUse(const CSSSelector& selector)
{
if (!isFastCheckableRightmostSelector(selector))
return false;
- for (selector = selector->tagHistory(); selector; selector = selector->tagHistory()) {
- if (!isFastCheckableRelation(selector->relation()))
+ for (const CSSSelector* current = selector.tagHistory(); current; current = current->tagHistory()) {
+ if (!isFastCheckableRelation(current->relation()))
return false;
- if (!isFastCheckableMatch(selector))
+ if (!isFastCheckableMatch(*current))
return false;
}
return true;
@@ -206,7 +206,7 @@ bool SelectorCheckerFastPath::canUse(const CSSSelector* selector)
bool SelectorCheckerFastPath::commonPseudoClassSelectorMatches(SelectorChecker::VisitedMatchType visitedMatchType) const
{
ASSERT(SelectorChecker::isCommonPseudoClassSelector(m_selector));
- switch (m_selector->pseudoType()) {
+ switch (m_selector.pseudoType()) {
case CSSSelector::PseudoLink:
case CSSSelector::PseudoAnyLink:
return m_element.isLink();
« no previous file with comments | « Source/core/css/SelectorCheckerFastPath.h ('k') | Source/core/css/SelectorFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698