Fix style sharing optimization to be fast again. Go back to using pointer compariso...
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Oct 2004 23:02:59 +0000 (23:02 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Oct 2004 23:02:59 +0000 (23:02 +0000)
cousins to share.

        Reviewed by darin

        * khtml/css/cssstyleselector.cpp:
        (khtml::CSSStyleSelector::locateCousinList):
        * khtml/rendering/render_object.cpp:
        (RenderObject::setStyleInternal):
        * khtml/rendering/render_object.h:
        * khtml/xml/dom_elementimpl.cpp:
        (ElementImpl::recalcStyle):

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/css/cssstyleselector.cpp
WebCore/khtml/rendering/render_object.cpp
WebCore/khtml/rendering/render_object.h
WebCore/khtml/xml/dom_elementimpl.cpp

index e8ea0525cef0f22f2e3b772b9f131ed8b5de06eb..b232d1fc69d9cfd2627b117f57db463fb49149e6 100644 (file)
@@ -1,3 +1,18 @@
+2004-10-05  David Hyatt  <hyatt@apple.com>
+
+       Fix style sharing optimization to be fast again.  Go back to using pointer comparisons when looking for
+       cousins to share.
+       
+        Reviewed by darin
+
+        * khtml/css/cssstyleselector.cpp:
+        (khtml::CSSStyleSelector::locateCousinList):
+        * khtml/rendering/render_object.cpp:
+        (RenderObject::setStyleInternal):
+        * khtml/rendering/render_object.h:
+        * khtml/xml/dom_elementimpl.cpp:
+        (ElementImpl::recalcStyle):
+
 2004-10-05  David Hyatt  <hyatt@apple.com>
 
        Fix lists so that they properly participate in line layout as though they are text (when text bullets are
index cb21f1fcec9dae258a5ef6f168737eb4acfe87c6..3acc6ed5151df626791646370a61f3cb9507206d 100644 (file)
@@ -534,7 +534,7 @@ NodeImpl* CSSStyleSelector::locateCousinList(ElementImpl* parent)
         for (n = parent->previousSibling(); n && !n->isElementNode(); n = n->previousSibling());
         int subcount = 0;
         while (n) {
-            if (elementsCanShareStyle(static_cast<ElementImpl*>(n), parent))
+            if (n->renderer() && n->renderer()->style() == parent->renderer()->style())
                 return n->lastChild();
             if (subcount++ == siblingThreshold)
                 return 0;
@@ -543,7 +543,7 @@ NodeImpl* CSSStyleSelector::locateCousinList(ElementImpl* parent)
         if (!n && parent->parentNode() && parent->parentNode()->isElementNode())
             n = locateCousinList(static_cast<ElementImpl*>(parent->parentNode()));
         while (n) {
-            if (elementsCanShareStyle(static_cast<ElementImpl*>(n), parent))
+            if (n->renderer() && n->renderer()->style() == parent->renderer()->style())
                 return n->lastChild();
             if (subcount++ == siblingThreshold)
                 return 0;
index 648763cd3d74fd9419371c04245758b579a686bc..d4e7705b87bd6bcda7d239b592e84f6299134feb 100644 (file)
@@ -1606,6 +1606,17 @@ void RenderObject::setStyle(RenderStyle *style)
         repaint();
 }
 
+void RenderObject::setStyleInternal(RenderStyle* st)
+{
+    if (m_style == st)
+        return;
+    if (m_style)
+        m_style->deref(renderArena());
+    m_style = st;
+    if (m_style)
+        m_style->ref();
+}
+
 QRect RenderObject::viewRect() const
 {
     return canvas()->viewRect();
index 9d47a42d437d73fd126c88606b03f9eee6ca45e9..5164ea02ee8dd049ed70669b556dd0007afc6e9f 100644 (file)
@@ -505,8 +505,12 @@ public:
     
     virtual void dirtyLinesFromChangedChild(RenderObject* child, bool adding = true);
     
-    // set the style of the object.
-    virtual void setStyle(RenderStyle *style);
+    // Set the style of the object and update the state of the object accordingly.
+    virtual void setStyle(RenderStyle* style);
+
+    // Updates only the local style ptr of the object.  Does not update the state of the object,
+    // and so only should be called when the style is known not to have changed (or from setStyle).
+    void setStyleInternal(RenderStyle* style);
 
     // returns the containing block level element for this element.
     RenderBlock *containingBlock() const;
index 38ff6df96f053fbfa95ec334ee30b0239a52a7c7..dfb2cdbd5ae2412c03db4ee9d944ae7ac93aa9be 100644 (file)
@@ -462,6 +462,14 @@ void ElementImpl::recalcStyle( StyleChange change )
                 m_render->setStyle(newStyle);
             }
         }
+        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());
 
         if ( change != Force) {