Title: [201075] trunk/Source/WebCore
Revision
201075
Author
[email protected]
Date
2016-05-18 07:21:37 -0700 (Wed, 18 May 2016)

Log Message

Resolve !important properties from different shadow trees in a single pass.
https://bugs.webkit.org/show_bug.cgi?id=157836

Reviewed by Andreas Kling.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::CascadedProperties::addImportantMatches):

Instead of doing multiple passes over increasing tree context ordinals collect matches with
non-zero ordinals to a vector and sort it to ascending order.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (201074 => 201075)


--- trunk/Source/WebCore/ChangeLog	2016-05-18 09:15:44 UTC (rev 201074)
+++ trunk/Source/WebCore/ChangeLog	2016-05-18 14:21:37 UTC (rev 201075)
@@ -1,3 +1,16 @@
+2016-05-18  Antti Koivisto  <[email protected]>
+
+        Resolve !important properties from different shadow trees in a single pass.
+        https://bugs.webkit.org/show_bug.cgi?id=157836
+
+        Reviewed by Andreas Kling.
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::CascadedProperties::addImportantMatches):
+
+        Instead of doing multiple passes over increasing tree context ordinals collect matches with
+        non-zero ordinals to a vector and sort it to ascending order.
+
 2016-05-18  Csaba Osztrogonác  <[email protected]>
 
         Fix the allinone-build after r198669

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (201074 => 201075)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2016-05-18 09:15:44 UTC (rev 201074)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2016-05-18 14:21:37 UTC (rev 201075)
@@ -2418,24 +2418,37 @@
     if (startIndex == -1)
         return;
 
-    unsigned highestTreeContextOrdinal = 0;
-    for (unsigned treeContextPass = 0; treeContextPass <= highestTreeContextOrdinal; ++treeContextPass) {
-        for (int i = startIndex; i <= endIndex; ++i) {
-            const MatchedProperties& matchedProperties = matchResult.matchedProperties()[i];
+    struct IndexAndOrdinal {
+        int index;
+        unsigned ordinal;
+    };
+    Vector<IndexAndOrdinal> shadowTreeMatches;
 
-            if (!hasImportantProperties(*matchedProperties.properties))
-                continue;
+    for (int i = startIndex; i <= endIndex; ++i) {
+        const MatchedProperties& matchedProperties = matchResult.matchedProperties()[i];
 
-            // For !important properties a later shadow tree wins. Do multiple passes to apply in correct order if needed.
-            // Matched properties are sorted in reverse tree context order so this is not needed for normal properties.
-            if (matchedProperties.treeContextOrdinal != treeContextPass) {
-                highestTreeContextOrdinal = std::max(matchedProperties.treeContextOrdinal, highestTreeContextOrdinal);
-                continue;
-            }
+        if (!hasImportantProperties(*matchedProperties.properties))
+            continue;
 
-            addMatch(matchResult, i, true, inheritedOnly);
+        if (matchedProperties.treeContextOrdinal) {
+            shadowTreeMatches.append({ i, matchedProperties.treeContextOrdinal });
+            continue;
         }
+
+        addMatch(matchResult, i, true, inheritedOnly);
     }
+
+    if (shadowTreeMatches.isEmpty())
+        return;
+
+    // For !important properties a later shadow tree wins.
+    // Match results are sorted in reverse tree context order so this is not needed for normal properties.
+    std::stable_sort(shadowTreeMatches.begin(), shadowTreeMatches.end(), [] (const IndexAndOrdinal& a, const IndexAndOrdinal& b) {
+        return a.ordinal < b.ordinal;
+    });
+
+    for (auto& match : shadowTreeMatches)
+        addMatch(matchResult, match.index, true, inheritedOnly);
 }
 
 void StyleResolver::CascadedProperties::applyDeferredProperties(StyleResolver& resolver, const MatchResult* matchResult)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to