Back out style sharing perf fix.
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Oct 2004 02:03:19 +0000 (02:03 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Oct 2004 02:03:19 +0000 (02:03 +0000)
        * khtml/css/cssstyleselector.cpp:
        (khtml::CSSStyleSelector::locateCousinList):
        (khtml::CSSStyleSelector::canShareStyleWithElement):
        (khtml::CSSStyleSelector::locateSharedStyle):
        * khtml/css/cssstyleselector.h:
        * khtml/html/html_elementimpl.h:
        (DOM::HTMLElementImpl::inlineStyleDecl):
        * khtml/xml/dom_elementimpl.cpp:
        (ElementImpl::recalcStyle):
        * khtml/xml/dom_elementimpl.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@7785 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/css/cssstyleselector.cpp
WebCore/khtml/css/cssstyleselector.h
WebCore/khtml/html/html_elementimpl.h
WebCore/khtml/xml/dom_elementimpl.cpp
WebCore/khtml/xml/dom_elementimpl.h

index a1cc841065b2026e0345d2f81937ca05b7bb3def..72fd6ef4b50a1dfef3923925113fcff55355a883 100644 (file)
@@ -1,3 +1,18 @@
+2004-10-06  David Hyatt  <hyatt@apple.com>
+
+       Back out style sharing perf fix.
+       
+        * khtml/css/cssstyleselector.cpp:
+        (khtml::CSSStyleSelector::locateCousinList):
+        (khtml::CSSStyleSelector::canShareStyleWithElement):
+        (khtml::CSSStyleSelector::locateSharedStyle):
+        * khtml/css/cssstyleselector.h:
+        * khtml/html/html_elementimpl.h:
+        (DOM::HTMLElementImpl::inlineStyleDecl):
+        * khtml/xml/dom_elementimpl.cpp:
+        (ElementImpl::recalcStyle):
+        * khtml/xml/dom_elementimpl.h:
+
 === Safari-166 ===
 
 2004-10-05  David Hyatt  <hyatt@apple.com>
index 0b2686e0c10c007d021b26dc37446c2d049d598a..7cfc653e81956cda7a057b516a567d5eaf881ca0 100644 (file)
@@ -529,67 +529,72 @@ const int siblingThreshold = 10;
 
 NodeImpl* CSSStyleSelector::locateCousinList(ElementImpl* parent)
 {
-    // FIXME: Investigate the difference between elementsCanShareStyle and a pointer compare of renderstyles.
-    if (parent && parent->renderer() && !parent->inlineStyleDecl() && !parent->hasID()) {
-        DOM::NodeImpl* n = parent->previousSibling();
-        RenderStyle* st = parent->renderer()->style();
-        int subcount = 0;
-        while (n) {
-            if (n->renderer() && n->renderer()->style() == st)
-                return n->lastChild();
-            if (subcount++ == siblingThreshold)
-                return 0;
-            n = n->previousSibling();
-        }
-        if (!n && parent->parentNode() && parent->parentNode()->isElementNode())
-            n = locateCousinList(static_cast<ElementImpl*>(parent->parentNode()));
-        while (n) {
-            if (n->renderer() && n->renderer()->style() == st)
-                return n->lastChild();
-            if (subcount++ == siblingThreshold)
-                return 0;
-            n = n->previousSibling();
+    if (parent && parent->isHTMLElement()) {
+        HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parent);
+        if (p->renderer() && !p->inlineStyleDecl() && !p->hasID()) {
+            DOM::NodeImpl* r = p->previousSibling();
+            int subcount = 0;
+            RenderStyle* st = p->renderer()->style();
+            while (r) {
+                if (r->renderer() && r->renderer()->style() == st)
+                    return r->lastChild();
+                if (subcount++ == siblingThreshold)
+                    return 0;
+                r = r->previousSibling();
+            }
+            if (!r)
+                r = locateCousinList(static_cast<ElementImpl*>(parent->parentNode()));
+            while (r) {
+                if (r->renderer() && r->renderer()->style() == st)
+                    return r->lastChild();
+                if (subcount++ == siblingThreshold)
+                    return 0;
+                r = r->previousSibling();
+            }
         }
     }
     return 0;
 }
 
-bool CSSStyleSelector::elementsCanShareStyle(ElementImpl* e1, ElementImpl* e2)
+bool CSSStyleSelector::canShareStyleWithElement(NodeImpl* n)
 {
-    bool mouseInside = e2->renderer() ? e2->renderer()->mouseInside() : false;
-    if (e1->renderer() && (e1->id() == e2->id()) && !e1->hasID() &&
-        (e1->hasClass() == e2->hasClass()) && !e1->inlineStyleDecl() &&
-        (e1->hasMappedAttributes() == e2->hasMappedAttributes()) &&
-        (e1->hasAnchor() == e2->hasAnchor()) && 
-        !e1->renderer()->style()->affectedByAttributeSelectors() &&
-        (e1->renderer()->mouseInside() == mouseInside) &&
-        (e1->active() == e2->active()) &&
-        (e1->focused() == e2->focused())) {
-        bool classesMatch = true;
-        if (e1->hasClass()) {
-            const AtomicString& class1 = e2->getAttribute(ATTR_CLASS);
-            const AtomicString& class2 = e1->getAttribute(ATTR_CLASS);
-            classesMatch = (class1 == class2);
-        }
-        
-        if (classesMatch) {
-            bool mappedAttrsMatch = true;
-            if (e1->hasMappedAttributes()) 
-                mappedAttrsMatch = static_cast<HTMLElementImpl*>(e1)->htmlAttributes()->mapsEquivalent(static_cast<HTMLElementImpl*>(e2)->htmlAttributes());
-            if (mappedAttrsMatch) {
-                bool anchorsMatch = true;
-                if (e1->hasAnchor()) {
-                    // We need to check to see if the visited state matches.
-                    QColor linkColor = e2->getDocument()->linkColor();
-                    QColor visitedColor = e2->getDocument()->visitedLinkColor();
-                    if (pseudoState == PseudoUnknown)
-                        checkPseudoState(element, e1->renderer()->style()->pseudoState() != PseudoAnyLink ||
-                                         linkColor != visitedColor);
-                    anchorsMatch = (pseudoState == e1->renderer()->style()->pseudoState());
+    if (n->isHTMLElement()) {
+        bool mouseInside = element->renderer() ? element->renderer()->mouseInside() : false;
+        HTMLElementImpl* s = static_cast<HTMLElementImpl*>(n);
+        if (s->renderer() && (s->id() == element->id()) && !s->hasID() &&
+            (s->hasClass() == element->hasClass()) && !s->inlineStyleDecl() &&
+            (s->hasMappedAttributes() == htmlElement->hasMappedAttributes()) &&
+            (s->hasAnchor() == element->hasAnchor()) && 
+            !s->renderer()->style()->affectedByAttributeSelectors() &&
+            (s->renderer()->mouseInside() == mouseInside) &&
+            (s->active() == element->active()) &&
+            (s->focused() == element->focused())) {
+            bool classesMatch = true;
+            if (s->hasClass()) {
+                const AtomicString& class1 = element->getAttribute(ATTR_CLASS);
+                const AtomicString& class2 = s->getAttribute(ATTR_CLASS);
+                classesMatch = (class1 == class2);
+            }
+            
+            if (classesMatch) {
+                bool mappedAttrsMatch = true;
+                if (s->hasMappedAttributes())
+                    mappedAttrsMatch = s->htmlAttributes()->mapsEquivalent(htmlElement->htmlAttributes());
+                if (mappedAttrsMatch) {
+                    bool anchorsMatch = true;
+                    if (s->hasAnchor()) {
+                        // We need to check to see if the visited state matches.
+                        QColor linkColor = element->getDocument()->linkColor();
+                        QColor visitedColor = element->getDocument()->visitedLinkColor();
+                        if (pseudoState == PseudoUnknown)
+                            checkPseudoState(element, s->renderer()->style()->pseudoState() != PseudoAnyLink ||
+                                             linkColor != visitedColor);
+                        anchorsMatch = (pseudoState == s->renderer()->style()->pseudoState());
+                    }
+                    
+                    if (anchorsMatch)
+                        return true;
                 }
-                
-                if (anchorsMatch)
-                    return true;
             }
         }
     }
@@ -598,22 +603,23 @@ bool CSSStyleSelector::elementsCanShareStyle(ElementImpl* e1, ElementImpl* e2)
 
 RenderStyle* CSSStyleSelector::locateSharedStyle()
 {
-    if (!element->inlineStyleDecl() && !element->hasID() && !element->getDocument()->usesSiblingRules()) {
+    if (htmlElement && !htmlElement->inlineStyleDecl() && !htmlElement->hasID() &&
+        !htmlElement->getDocument()->usesSiblingRules()) {
         // Check previous siblings.
         int count = 0;
         DOM::NodeImpl* n;
         for (n = element->previousSibling(); n && !n->isElementNode(); n = n->previousSibling());
         while (n) {
-            if (elementsCanShareStyle(static_cast<ElementImpl*>(n), element))
+            if (canShareStyleWithElement(n))
                 return n->renderer()->style();
             if (count++ == siblingThreshold)
                 return 0;
             for (n = n->previousSibling(); n && !n->isElementNode(); n = n->previousSibling());
         }
-        if (!n && element->parentNode() && element->parentNode()->isElementNode()
+        if (!n) 
             n = locateCousinList(static_cast<ElementImpl*>(element->parentNode()));
         while (n) {
-            if (elementsCanShareStyle(static_cast<ElementImpl*>(n), element))
+            if (canShareStyleWithElement(n))
                 return n->renderer()->style();
             if (count++ == siblingThreshold)
                 return 0;
@@ -623,6 +629,7 @@ RenderStyle* CSSStyleSelector::locateSharedStyle()
     return 0;
 }
 
+
 RenderStyle* CSSStyleSelector::styleForElement(ElementImpl* e, RenderStyle* defaultParent, bool allowSharing)
 {
     if (!e->getDocument()->haveStylesheetsLoaded()) {
index 64136e03c277176746664e256458541a2087a5a5..4ef9ee6cc6291e3a6cd5aa841079aa30c43e7888 100644 (file)
@@ -112,7 +112,7 @@ namespace khtml
 
         RenderStyle* locateSharedStyle();
         DOM::NodeImpl* locateCousinList(DOM::ElementImpl* parent);
-        bool elementsCanShareStyle(DOM::ElementImpl* e1, DOM::ElementImpl* e2);
+        bool canShareStyleWithElement(DOM::NodeImpl* n);
         
        bool strictParsing;
        
index 6bf1e9f724b75650dd3f9b50e83b4dd42f931921..2982b871267ac3b30800eeebc44f56817bcffc24 100644 (file)
@@ -168,7 +168,7 @@ public:
 
     virtual void click();
     
-    virtual CSSStyleDeclarationImpl* inlineStyleDecl() const { return m_inlineStyleDecl; }
+    CSSStyleDeclarationImpl* inlineStyleDecl() const { return m_inlineStyleDecl; }
     virtual CSSStyleDeclarationImpl* additionalAttributeStyleDecl();
     CSSStyleDeclarationImpl* getInlineStyleDecl();
     void createInlineStyleDecl();
index dfb2cdbd5ae2412c03db4ee9d944ae7ac93aa9be..70044f3e7e3b3135f43a0df944a12b84577a0466 100644 (file)
@@ -462,13 +462,14 @@ void ElementImpl::recalcStyle( StyleChange change )
                 m_render->setStyle(newStyle);
             }
         }
+        /* FIXME: Back this out for now.
         else if (m_render && newStyle && (getDocument()->usesSiblingRules() || getDocument()->usesDescendantRules())) {
             // Although no change occurred, we use the new style so that the cousin style sharing code won't get
             // fooled into believing this style is the same.  This is only necessary if the document actually uses
             // sibling/descendant rules, since otherwise it isn't possible for ancestor styles to affect sharing of
             // descendants.
             m_render->setStyleInternal(newStyle);
-        }
+        }*/
 
         newStyle->deref(getDocument()->renderArena());
 
index e0159401deddbdc811bae0954028fb6241642a25..dbb55ddebdf3289e9b4c47cfb21c2bd81a177bed 100644 (file)
@@ -196,9 +196,6 @@ public:
     // State of the element.
     virtual QString state() { return QString::null; }
 
-    virtual CSSStyleDeclarationImpl* inlineStyleDecl() const { return 0; }
-    virtual bool hasMappedAttributes() const { return false; }
-
     virtual void attach();
     virtual void detach();
     virtual khtml::RenderStyle *styleForRenderer(khtml::RenderObject *parent);