Title: [228313] trunk/Source/WebCore
Revision
228313
Author
an...@apple.com
Date
2018-02-09 01:11:05 -0800 (Fri, 09 Feb 2018)

Log Message

Move compiled selectors to StyleRule
https://bugs.webkit.org/show_bug.cgi?id=182602

Reviewed by Zalan Bujtas.

Currently they are owned by RuleData. Several RuleData objects can refer to the same StyleRule, requiring recompilation.
Compiled selectors are context-independent so they can be shared between all clients.

* WebCore.xcodeproj/project.pbxproj:
* css/CSSSelectorList.cpp:
(WebCore::CSSSelectorList::listSize const):

Compute the number of complex selectors on the list.

* css/CSSSelectorList.h:
* css/DocumentRuleSets.cpp:
(WebCore::makeRuleSet):
(WebCore::DocumentRuleSets::classInvalidationRuleSets const):

Pass around list index along with the selector index (compiled selectors are found by list index).

* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::ruleMatches):
* css/RuleSet.cpp:
(WebCore::RuleData::RuleData):
* css/RuleSet.h:
(WebCore::RuleData::compilationStatus const): Deleted.
(WebCore::RuleData::compiledSelectorCodeRef const): Deleted.
(WebCore::RuleData::setCompiledSelector const): Deleted.
(WebCore::RuleData::~RuleData): Deleted.
(WebCore::RuleData::compiledSelectorUsed const): Deleted.
* css/StyleRule.cpp:
(WebCore::StyleRule::StyleRule):
* css/StyleRule.h:

    Add CompiledSelector member.

* cssjit/CompiledSelector.h: Added.

    Move to a header of its own to keeps dependencies simple.

(WebCore::SelectorCompilationStatus::SelectorCompilationStatus):
(WebCore::SelectorCompilationStatus::operator Status const):
* cssjit/SelectorCompiler.h:
(): Deleted.
(WebCore::SelectorCompilationStatus::SelectorCompilationStatus): Deleted.
(WebCore::SelectorCompilationStatus::operator Status const): Deleted.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228312 => 228313)


--- trunk/Source/WebCore/ChangeLog	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/ChangeLog	2018-02-09 09:11:05 UTC (rev 228313)
@@ -1,3 +1,53 @@
+2018-02-09  Antti Koivisto  <an...@apple.com>
+
+        Move compiled selectors to StyleRule
+        https://bugs.webkit.org/show_bug.cgi?id=182602
+
+        Reviewed by Zalan Bujtas.
+
+        Currently they are owned by RuleData. Several RuleData objects can refer to the same StyleRule, requiring recompilation.
+        Compiled selectors are context-independent so they can be shared between all clients.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSSelectorList.cpp:
+        (WebCore::CSSSelectorList::listSize const):
+
+        Compute the number of complex selectors on the list.
+
+        * css/CSSSelectorList.h:
+        * css/DocumentRuleSets.cpp:
+        (WebCore::makeRuleSet):
+        (WebCore::DocumentRuleSets::classInvalidationRuleSets const):
+
+        Pass around list index along with the selector index (compiled selectors are found by list index).
+
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::ruleMatches):
+        * css/RuleSet.cpp:
+        (WebCore::RuleData::RuleData):
+        * css/RuleSet.h:
+        (WebCore::RuleData::compilationStatus const): Deleted.
+        (WebCore::RuleData::compiledSelectorCodeRef const): Deleted.
+        (WebCore::RuleData::setCompiledSelector const): Deleted.
+        (WebCore::RuleData::~RuleData): Deleted.
+        (WebCore::RuleData::compiledSelectorUsed const): Deleted.
+        * css/StyleRule.cpp:
+        (WebCore::StyleRule::StyleRule):
+        * css/StyleRule.h:
+
+            Add CompiledSelector member.
+
+        * cssjit/CompiledSelector.h: Added.
+
+            Move to a header of its own to keeps dependencies simple.
+
+        (WebCore::SelectorCompilationStatus::SelectorCompilationStatus):
+        (WebCore::SelectorCompilationStatus::operator Status const):
+        * cssjit/SelectorCompiler.h:
+        (): Deleted.
+        (WebCore::SelectorCompilationStatus::SelectorCompilationStatus): Deleted.
+        (WebCore::SelectorCompilationStatus::operator Status const): Deleted.
+
 2018-02-08  Antoine Quint  <grao...@apple.com>
 
         [Web Animations] Always expose "composite" in output of getKeyframes()

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (228312 => 228313)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-02-09 09:11:05 UTC (rev 228313)
@@ -13998,6 +13998,7 @@
 		E43AF8E41AC5B7DD00CA717E /* CacheValidation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheValidation.cpp; sourceTree = "<group>"; };
 		E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheValidation.h; sourceTree = "<group>"; };
 		E440AA951C68420800A265CC /* ElementAndTextDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementAndTextDescendantIterator.h; sourceTree = "<group>"; };
+		E4451077202C7E0100657D33 /* CompiledSelector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompiledSelector.h; sourceTree = "<group>"; };
 		E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAudioElement.cpp; sourceTree = "<group>"; };
 		E44613900CD6331000FADA75 /* HTMLAudioElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLAudioElement.h; sourceTree = "<group>"; };
 		E44613910CD6331000FADA75 /* HTMLAudioElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLAudioElement.idl; sourceTree = "<group>"; };
@@ -15965,6 +15966,7 @@
 		26B9998D1803ADFA00D01121 /* cssjit */ = {
 			isa = PBXGroup;
 			children = (
+				E4451077202C7E0100657D33 /* CompiledSelector.h */,
 				26B999921803B9D900D01121 /* FunctionCall.h */,
 				26B9998E1803AE7200D01121 /* RegisterAllocator.h */,
 				26B999941804D54200D01121 /* SelectorCompiler.cpp */,

Modified: trunk/Source/WebCore/css/CSSSelectorList.cpp (228312 => 228313)


--- trunk/Source/WebCore/css/CSSSelectorList.cpp	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/CSSSelectorList.cpp	2018-02-09 09:11:05 UTC (rev 228313)
@@ -95,6 +95,20 @@
     return (current - m_selectorArray) + 1;
 }
 
+unsigned CSSSelectorList::listSize() const
+{
+    if (!m_selectorArray)
+        return 0;
+    unsigned size = 1;
+    CSSSelector* current = m_selectorArray;
+    while (!current->isLastInSelectorList()) {
+        if (current->isLastInTagHistory())
+            ++size;
+        ++current;
+    }
+    return size;
+}
+
 CSSSelectorList& CSSSelectorList::operator=(CSSSelectorList&& other)
 {
     deleteSelectors();

Modified: trunk/Source/WebCore/css/CSSSelectorList.h (228312 => 228313)


--- trunk/Source/WebCore/css/CSSSelectorList.h	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/CSSSelectorList.h	2018-02-09 09:11:05 UTC (rev 228313)
@@ -66,6 +66,7 @@
     void buildSelectorsText(StringBuilder&) const;
 
     unsigned componentCount() const;
+    unsigned listSize() const;
 
     CSSSelectorList& operator=(CSSSelectorList&&);
 

Modified: trunk/Source/WebCore/css/DocumentRuleSets.cpp (228312 => 228313)


--- trunk/Source/WebCore/css/DocumentRuleSets.cpp	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/DocumentRuleSets.cpp	2018-02-09 09:11:05 UTC (rev 228313)
@@ -114,7 +114,7 @@
         return nullptr;
     auto ruleSet = std::make_unique<RuleSet>();
     for (size_t i = 0; i < size; ++i)
-        ruleSet->addRule(rules[i].rule, rules[i].selectorIndex);
+        ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].selectorListIndex);
     ruleSet->shrinkToFit();
     return ruleSet;
 }
@@ -187,7 +187,7 @@
             auto& ruleSet = matchElementArray[arrayIndex];
             if (!ruleSet)
                 ruleSet = std::make_unique<RuleSet>();
-            ruleSet->addRule(feature.rule, feature.selectorIndex);
+            ruleSet->addRule(feature.rule, feature.selectorIndex, feature.selectorListIndex);
             if (feature.invalidationSelector)
                 invalidationSelectorArray[arrayIndex].append(feature.invalidationSelector);
         }

Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (228312 => 228313)


--- trunk/Source/WebCore/css/ElementRuleCollector.cpp	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp	2018-02-09 09:11:05 UTC (rev 228313)
@@ -383,18 +383,16 @@
     }
 
 #if ENABLE(CSS_SELECTOR_JIT)
-    void* compiledSelectorChecker = ruleData.compiledSelectorCodeRef().code().executableAddress();
-    if (!compiledSelectorChecker && ruleData.compilationStatus() == SelectorCompilationStatus::NotCompiled) {
-        SelectorCompilationStatus compilationStatus;
-        JSC::MacroAssemblerCodeRef compiledSelectorCodeRef;
-        compilationStatus = SelectorCompiler::compileSelector(ruleData.selector(), SelectorCompiler::SelectorContext::RuleCollector, compiledSelectorCodeRef);
+    auto& compiledSelector = ruleData.rule()->compiledSelectorForListIndex(ruleData.selectorListIndex());
+    void* compiledSelectorChecker = compiledSelector.codeRef.code().executableAddress();
+    if (!compiledSelectorChecker && compiledSelector.status == SelectorCompilationStatus::NotCompiled) {
+        compiledSelector.status = SelectorCompiler::compileSelector(ruleData.selector(), SelectorCompiler::SelectorContext::RuleCollector, compiledSelector.codeRef);
 
-        ruleData.setCompiledSelector(compilationStatus, compiledSelectorCodeRef);
-        compiledSelectorChecker = ruleData.compiledSelectorCodeRef().code().executableAddress();
+        compiledSelectorChecker = compiledSelector.codeRef.code().executableAddress();
     }
 
-    if (compiledSelectorChecker && ruleData.compilationStatus() == SelectorCompilationStatus::SimpleSelectorChecker) {
-        SelectorCompiler::RuleCollectorSimpleSelectorChecker selectorChecker = SelectorCompiler::ruleCollectorSimpleSelectorCheckerFunction(compiledSelectorChecker, ruleData.compilationStatus());
+    if (compiledSelectorChecker && compiledSelector.status == SelectorCompilationStatus::SimpleSelectorChecker) {
+        auto selectorChecker = SelectorCompiler::ruleCollectorSimpleSelectorCheckerFunction(compiledSelectorChecker, compiledSelector.status);
 #if !ASSERT_MSG_DISABLED
         unsigned ignoreSpecificity;
         ASSERT_WITH_MESSAGE(!selectorChecker(&m_element, &ignoreSpecificity) || m_pseudoStyleRequest.pseudoId == NOPSEUDO, "When matching pseudo elements, we should never compile a selector checker without context unless it cannot match anything.");
@@ -420,12 +418,12 @@
     bool selectorMatches;
 #if ENABLE(CSS_SELECTOR_JIT)
     if (compiledSelectorChecker) {
-        ASSERT(ruleData.compilationStatus() == SelectorCompilationStatus::SelectorCheckerWithCheckingContext);
+        ASSERT(compiledSelector.status == SelectorCompilationStatus::SelectorCheckerWithCheckingContext);
 
-        SelectorCompiler::RuleCollectorSelectorCheckerWithCheckingContext selectorChecker = SelectorCompiler::ruleCollectorSelectorCheckerFunctionWithCheckingContext(compiledSelectorChecker, ruleData.compilationStatus());
+        auto selectorChecker = SelectorCompiler::ruleCollectorSelectorCheckerFunctionWithCheckingContext(compiledSelectorChecker, compiledSelector.status);
 
 #if CSS_SELECTOR_JIT_PROFILING
-        ruleData.compiledSelectorUsed();
+        compiledSelector.useCount++;
 #endif
         selectorMatches = selectorChecker(&m_element, &context, &specificity);
     } else

Modified: trunk/Source/WebCore/css/RuleFeature.cpp (228312 => 228313)


--- trunk/Source/WebCore/css/RuleFeature.cpp	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/RuleFeature.cpp	2018-02-09 09:11:05 UTC (rev 228313)
@@ -168,24 +168,23 @@
     SelectorFeatures selectorFeatures;
     recursivelyCollectFeaturesFromSelector(selectorFeatures, *ruleData.selector());
     if (selectorFeatures.hasSiblingSelector)
-        siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
+        siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex()));
     if (ruleData.containsUncommonAttributeSelector())
-        uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
+        uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex()));
 
     for (auto& nameAndMatch : selectorFeatures.classes) {
         classRules.ensure(nameAndMatch.first, [] {
             return std::make_unique<Vector<RuleFeature>>();
-        }).iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), nameAndMatch.second));
+        }).iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex(), nameAndMatch.second));
         if (nameAndMatch.second == MatchElement::Host)
             classesAffectingHost.add(nameAndMatch.first);
     }
-
     for (auto& selectorAndMatch : selectorFeatures.attributes) {
         auto* selector = selectorAndMatch.first;
         auto matchElement = selectorAndMatch.second;
         attributeRules.ensure(selector->attribute().localName().convertToASCIILowercase(), [] {
             return std::make_unique<Vector<RuleFeature>>();
-        }).iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), matchElement, selector));
+        }).iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex(), matchElement, selector));
         if (matchElement == MatchElement::Host)
             attributesAffectingHost.add(selector->attribute().localName().convertToASCIILowercase());
     }

Modified: trunk/Source/WebCore/css/RuleFeature.h (228312 => 228313)


--- trunk/Source/WebCore/css/RuleFeature.h	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/RuleFeature.h	2018-02-09 09:11:05 UTC (rev 228313)
@@ -37,9 +37,10 @@
 constexpr unsigned matchElementCount = static_cast<unsigned>(MatchElement::Host) + 1;
 
 struct RuleFeature {
-    RuleFeature(StyleRule* rule, unsigned selectorIndex, std::optional<MatchElement> matchElement = std::nullopt, const CSSSelector* invalidationSelector = nullptr)
+    RuleFeature(StyleRule* rule, unsigned selectorIndex, unsigned selectorListIndex, std::optional<MatchElement> matchElement = std::nullopt, const CSSSelector* invalidationSelector = nullptr)
         : rule(rule)
         , selectorIndex(selectorIndex)
+        , selectorListIndex(selectorListIndex)
         , matchElement(matchElement)
         , invalidationSelector(invalidationSelector)
     {
@@ -46,6 +47,7 @@
     }
     StyleRule* rule;
     unsigned selectorIndex;
+    unsigned selectorListIndex;
     std::optional<MatchElement> matchElement;
     const CSSSelector* invalidationSelector;
 };

Modified: trunk/Source/WebCore/css/RuleSet.cpp (228312 => 228313)


--- trunk/Source/WebCore/css/RuleSet.cpp	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/RuleSet.cpp	2018-02-09 09:11:05 UTC (rev 228313)
@@ -148,9 +148,10 @@
     return PropertyWhitelistNone;
 }
 
-RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position)
+RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned selectorListIndex, unsigned position)
     : m_rule(rule)
     , m_selectorIndex(selectorIndex)
+    , m_selectorListIndex(selectorListIndex)
     , m_position(position)
     , m_matchBasedOnRuleHash(static_cast<unsigned>(computeMatchBasedOnRuleHash(*selector())))
     , m_canMatchPseudoElement(selectorCanMatchPseudoElement(*selector()))
@@ -158,9 +159,6 @@
     , m_linkMatchType(SelectorChecker::determineLinkMatchType(selector()))
     , m_propertyWhitelistType(determinePropertyWhitelistType(selector()))
     , m_descendantSelectorIdentifierHashes(SelectorFilter::collectHashes(*selector()))
-#if ENABLE(CSS_SELECTOR_JIT) && CSS_SELECTOR_JIT_PROFILING
-    , m_compiledSelectorUseCount(0)
-#endif
 {
     ASSERT(m_position == position);
     ASSERT(m_selectorIndex == selectorIndex);
@@ -201,9 +199,9 @@
     return leftmostSelector->match() == CSSSelector::PseudoClass && leftmostSelector->pseudoClassType() == CSSSelector::PseudoClassHost;
 }
 
-void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex)
+void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex, unsigned selectorListIndex)
 {
-    RuleData ruleData(rule, selectorIndex, m_ruleCount++);
+    RuleData ruleData(rule, selectorIndex, selectorListIndex, m_ruleCount++);
     m_features.collectFeatures(ruleData);
 
     unsigned classBucketSize = 0;
@@ -404,8 +402,9 @@
 
 void RuleSet::addStyleRule(StyleRule* rule)
 {
+    unsigned selectorListIndex = 0;
     for (size_t selectorIndex = 0; selectorIndex != notFound; selectorIndex = rule->selectorList().indexOfNextSelectorAfter(selectorIndex))
-        addRule(rule, selectorIndex);
+        addRule(rule, selectorIndex, selectorListIndex++);
 }
 
 bool RuleSet::hasShadowPseudoElementRules() const

Modified: trunk/Source/WebCore/css/RuleSet.h (228312 => 228313)


--- trunk/Source/WebCore/css/RuleSet.h	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/RuleSet.h	2018-02-09 09:11:05 UTC (rev 228313)
@@ -59,12 +59,13 @@
 public:
     static const unsigned maximumSelectorComponentCount = 8192;
 
-    RuleData(StyleRule*, unsigned selectorIndex, unsigned position);
+    RuleData(StyleRule*, unsigned selectorIndex, unsigned selectorListIndex, unsigned position);
 
     unsigned position() const { return m_position; }
     StyleRule* rule() const { return m_rule.get(); }
     const CSSSelector* selector() const { return m_rule->selectorList().selectorAt(m_selectorIndex); }
     unsigned selectorIndex() const { return m_selectorIndex; }
+    unsigned selectorListIndex() const { return m_selectorListIndex; }
 
     bool canMatchPseudoElement() const { return m_canMatchPseudoElement; }
     MatchBasedOnRuleHash matchBasedOnRuleHash() const { return static_cast<MatchBasedOnRuleHash>(m_matchBasedOnRuleHash); }
@@ -75,27 +76,10 @@
 
     void disableSelectorFiltering() { m_descendantSelectorIdentifierHashes[0] = 0; }
 
-#if ENABLE(CSS_SELECTOR_JIT)
-    SelectorCompilationStatus compilationStatus() const { return m_compilationStatus; }
-    JSC::MacroAssemblerCodeRef compiledSelectorCodeRef() const { return m_compiledSelectorCodeRef; }
-    void setCompiledSelector(SelectorCompilationStatus status, JSC::MacroAssemblerCodeRef codeRef) const
-    {
-        m_compilationStatus = status;
-        m_compiledSelectorCodeRef = codeRef;
-    }
-#if CSS_SELECTOR_JIT_PROFILING
-    ~RuleData()
-    {
-        if (m_compiledSelectorCodeRef.code().executableAddress())
-            dataLogF("RuleData compiled selector %d \"%s\"\n", m_compiledSelectorUseCount, selector()->selectorText().utf8().data());
-    }
-    void compiledSelectorUsed() const { m_compiledSelectorUseCount++; }
-#endif
-#endif // ENABLE(CSS_SELECTOR_JIT)
-
 private:
     RefPtr<StyleRule> m_rule;
-    unsigned m_selectorIndex : 13;
+    unsigned m_selectorIndex : 16;
+    unsigned m_selectorListIndex : 16;
     // This number was picked fairly arbitrarily. We can probably lower it if we need to.
     // Some simple testing showed <100,000 RuleData's on large sites.
     unsigned m_position : 18;
@@ -105,25 +89,9 @@
     unsigned m_linkMatchType : 2; //  SelectorChecker::LinkMatchMask
     unsigned m_propertyWhitelistType : 2;
     SelectorFilter::Hashes m_descendantSelectorIdentifierHashes;
-#if ENABLE(CSS_SELECTOR_JIT)
-    mutable SelectorCompilationStatus m_compilationStatus;
-    mutable JSC::MacroAssemblerCodeRef m_compiledSelectorCodeRef;
-#if CSS_SELECTOR_JIT_PROFILING
-    mutable unsigned m_compiledSelectorUseCount;
-#endif
-#endif // ENABLE(CSS_SELECTOR_JIT)
 };
     
 struct SameSizeAsRuleData {
-#if ENABLE(CSS_SELECTOR_JIT)
-    unsigned compilationStatus;
-    void* compiledSelectorPointer;
-    void* codeRefPtr;
-#if CSS_SELECTOR_JIT_PROFILING
-    unsigned compiledSelectorUseCount;
-#endif
-#endif // ENABLE(CSS_SELECTOR_JIT)
-
     void* a;
     unsigned b;
     unsigned c;
@@ -152,7 +120,7 @@
     void addRulesFromSheet(StyleSheetContents&, const MediaQueryEvaluator&, StyleResolver* = 0);
 
     void addStyleRule(StyleRule*);
-    void addRule(StyleRule*, unsigned selectorIndex);
+    void addRule(StyleRule*, unsigned selectorIndex, unsigned selectorListIndex);
     void addPageRule(StyleRulePage*);
     void addToRuleSet(const AtomicString& key, AtomRuleMap&, const RuleData&);
     void shrinkToFit();

Modified: trunk/Source/WebCore/css/StyleRule.cpp (228312 => 228313)


--- trunk/Source/WebCore/css/StyleRule.cpp	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/StyleRule.cpp	2018-02-09 09:11:05 UTC (rev 228313)
@@ -191,6 +191,9 @@
     : StyleRuleBase(o)
     , m_properties(o.properties().mutableCopy())
     , m_selectorList(o.m_selectorList)
+#if ENABLE(CSS_SELECTOR_JIT)
+    , m_compiledSelectors(o.m_compiledSelectors)
+#endif
 {
 }
 

Modified: trunk/Source/WebCore/css/StyleRule.h (228312 => 228313)


--- trunk/Source/WebCore/css/StyleRule.h	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/css/StyleRule.h	2018-02-09 09:11:05 UTC (rev 228313)
@@ -22,6 +22,7 @@
 #pragma once
 
 #include "CSSSelectorList.h"
+#include "CompiledSelector.h"
 #include "StyleProperties.h"
 #include <wtf/RefPtr.h>
 #include <wtf/TypeCasts.h>
@@ -139,6 +140,15 @@
 
     Vector<RefPtr<StyleRule>> splitIntoMultipleRulesWithMaximumSelectorComponentCount(unsigned) const;
 
+#if ENABLE(CSS_SELECTOR_JIT)
+    CompiledSelector& compiledSelectorForListIndex(unsigned index)
+    {
+        if (m_compiledSelectors.isEmpty())
+            m_compiledSelectors.grow(m_selectorList.listSize());
+        return m_compiledSelectors[index];
+    }
+#endif
+
     static unsigned averageSizeInBytes();
 
 private:
@@ -149,6 +159,10 @@
 
     mutable Ref<StylePropertiesBase> m_properties;
     CSSSelectorList m_selectorList;
+
+#if ENABLE(CSS_SELECTOR_JIT)
+    Vector<CompiledSelector> m_compiledSelectors;
+#endif
 };
 
 inline const StyleProperties* StyleRule::propertiesWithoutDeferredParsing() const

Added: trunk/Source/WebCore/cssjit/CompiledSelector.h (0 => 228313)


--- trunk/Source/WebCore/cssjit/CompiledSelector.h	                        (rev 0)
+++ trunk/Source/WebCore/cssjit/CompiledSelector.h	2018-02-09 09:11:05 UTC (rev 228313)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2013, 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(CSS_SELECTOR_JIT)
+
+#include <_javascript_Core/MacroAssemblerCodeRef.h>
+
+namespace WebCore {
+
+class SelectorCompilationStatus {
+public:
+    enum Status {
+        NotCompiled,
+        CannotCompile,
+        SimpleSelectorChecker,
+        SelectorCheckerWithCheckingContext
+    };
+
+    SelectorCompilationStatus()
+        : m_status(NotCompiled)
+    { }
+
+    SelectorCompilationStatus(Status status)
+        : m_status(status)
+    { }
+
+    operator Status() const { return m_status; }
+
+private:
+    Status m_status;
+};
+
+struct CompiledSelector {
+    SelectorCompilationStatus status;
+    JSC::MacroAssemblerCodeRef codeRef;
+#if defined(CSS_SELECTOR_JIT_PROFILING) && CSS_SELECTOR_JIT_PROFILING
+    unsigned useCount { 0 };
+#endif
+};
+
+}
+
+#endif

Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.h (228312 => 228313)


--- trunk/Source/WebCore/cssjit/SelectorCompiler.h	2018-02-09 07:31:16 UTC (rev 228312)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.h	2018-02-09 09:11:05 UTC (rev 228313)
@@ -27,44 +27,16 @@
 
 #if ENABLE(CSS_SELECTOR_JIT)
 
+#include "CompiledSelector.h"
 #include "SelectorChecker.h"
-#include <_javascript_Core/MacroAssemblerCodeRef.h>
 
 #define CSS_SELECTOR_JIT_PROFILING 0
 
-namespace JSC {
-class MacroAssemblerCodeRef;
-}
-
 namespace WebCore {
 
 class CSSSelector;
 class Element;
-class RenderStyle;
 
-class SelectorCompilationStatus {
-public:
-    enum Status {
-        NotCompiled,
-        CannotCompile,
-        SimpleSelectorChecker,
-        SelectorCheckerWithCheckingContext
-    };
-
-    SelectorCompilationStatus()
-        : m_status(NotCompiled)
-    { }
-
-    SelectorCompilationStatus(Status status)
-        : m_status(status)
-    { }
-
-    operator Status() const { return m_status; }
-
-private:
-    Status m_status;
-};
-
 namespace SelectorCompiler {
 
 enum class SelectorContext {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to