Title: [90882] trunk/Source/WebCore
Revision
90882
Author
[email protected]
Date
2011-07-12 20:30:36 -0700 (Tue, 12 Jul 2011)

Log Message

Make RenderObject::containingBlock virtual for better speed and clarity
https://bugs.webkit.org/show_bug.cgi?id=64318

Reviewed by Darin Adler.

No new tests, performance refactoring.

On some of my test cases, this method takes between 3 and 5% of the time spend.
The method makes 2 calls to virtual methods which could be moved to their overriden
version of containingBlock if we made it virtual.

That's what this patch does. It saves between 1 and 2% on some synthetic test cases
as well as made the current method shorter.

* rendering/RenderObject.cpp:
(WebCore::RenderObject::containingBlock): Removed code for RenderView and RenderTableCell,
replaced by ASSERTs.

* rendering/RenderObject.h: Made containingBlock virtual.

* rendering/RenderTableCell.h:
(WebCore::RenderTableCell::containingBlock):
* rendering/RenderView.h:
(WebCore::RenderView::containingBlock):
The code moved from RenderObject is inlined in those 2 methods.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (90881 => 90882)


--- trunk/Source/WebCore/ChangeLog	2011-07-13 02:41:21 UTC (rev 90881)
+++ trunk/Source/WebCore/ChangeLog	2011-07-13 03:30:36 UTC (rev 90882)
@@ -1,3 +1,31 @@
+2011-07-12  Julien Chaffraix  <[email protected]>
+
+        Make RenderObject::containingBlock virtual for better speed and clarity
+        https://bugs.webkit.org/show_bug.cgi?id=64318
+
+        Reviewed by Darin Adler.
+
+        No new tests, performance refactoring.
+
+        On some of my test cases, this method takes between 3 and 5% of the time spend.
+        The method makes 2 calls to virtual methods which could be moved to their overriden
+        version of containingBlock if we made it virtual.
+
+        That's what this patch does. It saves between 1 and 2% on some synthetic test cases
+        as well as made the current method shorter.
+
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::containingBlock): Removed code for RenderView and RenderTableCell,
+        replaced by ASSERTs.
+
+        * rendering/RenderObject.h: Made containingBlock virtual.
+
+        * rendering/RenderTableCell.h:
+        (WebCore::RenderTableCell::containingBlock):
+        * rendering/RenderView.h:
+        (WebCore::RenderView::containingBlock):
+        The code moved from RenderObject is inlined in those 2 methods.
+
 2011-07-12  James Robinson  <[email protected]>
 
         [chromium] Chromium win build fix.

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (90881 => 90882)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2011-07-13 02:41:21 UTC (rev 90881)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2011-07-13 03:30:36 UTC (rev 90882)
@@ -600,16 +600,9 @@
 
 RenderBlock* RenderObject::containingBlock() const
 {
-    if (isTableCell()) {
-        const RenderTableCell* cell = toRenderTableCell(this);
-        if (parent() && cell->section())
-            return cell->table();
-        return 0;
-    }
+    ASSERT(!isTableCell());
+    ASSERT(!isRenderView());
 
-    if (isRenderView())
-        return const_cast<RenderView*>(toRenderView(this));
-
     RenderObject* o = parent();
     if (!isText() && m_style->position() == FixedPosition) {
         while (o && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock()))

Modified: trunk/Source/WebCore/rendering/RenderObject.h (90881 => 90882)


--- trunk/Source/WebCore/rendering/RenderObject.h	2011-07-13 02:41:21 UTC (rev 90881)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2011-07-13 03:30:36 UTC (rev 90882)
@@ -571,7 +571,7 @@
     void setStyleInternal(PassRefPtr<RenderStyle>);
 
     // returns the containing block level element for this element.
-    RenderBlock* containingBlock() const;
+    virtual RenderBlock* containingBlock() const;
 
     // Convert the given local point to absolute coordinates
     // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.

Modified: trunk/Source/WebCore/rendering/RenderTableCell.cpp (90881 => 90882)


--- trunk/Source/WebCore/rendering/RenderTableCell.cpp	2011-07-13 02:41:21 UTC (rev 90881)
+++ trunk/Source/WebCore/rendering/RenderTableCell.cpp	2011-07-13 03:30:36 UTC (rev 90882)
@@ -319,6 +319,13 @@
     setHasBoxDecorations(true);
 }
 
+RenderBlock* RenderTableCell::containingBlock() const
+{
+    if (parent() && section())
+        return table();
+    return 0;
+}
+
 // The following rules apply for resolving conflicts and figuring out which border
 // to use.
 // (1) Borders with the 'border-style' of 'hidden' take precedence over all other conflicting 

Modified: trunk/Source/WebCore/rendering/RenderTableCell.h (90881 => 90882)


--- trunk/Source/WebCore/rendering/RenderTableCell.h	2011-07-13 02:41:21 UTC (rev 90881)
+++ trunk/Source/WebCore/rendering/RenderTableCell.h	2011-07-13 03:30:36 UTC (rev 90882)
@@ -137,6 +137,8 @@
 
     virtual bool isTableCell() const { return true; }
 
+    virtual RenderBlock* containingBlock() const;
+
     virtual void willBeDestroyed();
 
     virtual void computeLogicalWidth();

Modified: trunk/Source/WebCore/rendering/RenderView.cpp (90881 => 90882)


--- trunk/Source/WebCore/rendering/RenderView.cpp	2011-07-13 02:41:21 UTC (rev 90881)
+++ trunk/Source/WebCore/rendering/RenderView.cpp	2011-07-13 03:30:36 UTC (rev 90882)
@@ -257,6 +257,11 @@
     return true;
 }
 
+RenderBlock* RenderView::containingBlock() const
+{
+    return const_cast<RenderView*>(this);
+}
+
 void RenderView::repaintViewRectangle(const IntRect& ur, bool immediate)
 {
     if (!shouldRepaint(ur))

Modified: trunk/Source/WebCore/rendering/RenderView.h (90881 => 90882)


--- trunk/Source/WebCore/rendering/RenderView.h	2011-07-13 02:41:21 UTC (rev 90881)
+++ trunk/Source/WebCore/rendering/RenderView.h	2011-07-13 03:30:36 UTC (rev 90882)
@@ -170,6 +170,8 @@
 private:
     bool shouldRepaint(const IntRect& r) const;
     
+    virtual RenderBlock* containingBlock() const;
+
     // These functions may only be accessed by LayoutStateMaintainer.
     bool pushLayoutState(RenderBox* renderer, const IntSize& offset, int pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
     {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to