Changeset 90882 in webkit


Ignore:
Timestamp:
Jul 12, 2011 8:30:36 PM (13 years ago)
Author:
jchaffraix@webkit.org
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.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r90874 r90882  
     12011-07-12  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Make RenderObject::containingBlock virtual for better speed and clarity
     4        https://bugs.webkit.org/show_bug.cgi?id=64318
     5
     6        Reviewed by Darin Adler.
     7
     8        No new tests, performance refactoring.
     9
     10        On some of my test cases, this method takes between 3 and 5% of the time spend.
     11        The method makes 2 calls to virtual methods which could be moved to their overriden
     12        version of containingBlock if we made it virtual.
     13
     14        That's what this patch does. It saves between 1 and 2% on some synthetic test cases
     15        as well as made the current method shorter.
     16
     17        * rendering/RenderObject.cpp:
     18        (WebCore::RenderObject::containingBlock): Removed code for RenderView and RenderTableCell,
     19        replaced by ASSERTs.
     20
     21        * rendering/RenderObject.h: Made containingBlock virtual.
     22
     23        * rendering/RenderTableCell.h:
     24        (WebCore::RenderTableCell::containingBlock):
     25        * rendering/RenderView.h:
     26        (WebCore::RenderView::containingBlock):
     27        The code moved from RenderObject is inlined in those 2 methods.
     28
    1292011-07-12  James Robinson  <jamesr@chromium.org>
    230
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r90734 r90882  
    601601RenderBlock* RenderObject::containingBlock() const
    602602{
    603     if (isTableCell()) {
    604         const RenderTableCell* cell = toRenderTableCell(this);
    605         if (parent() && cell->section())
    606             return cell->table();
    607         return 0;
    608     }
    609 
    610     if (isRenderView())
    611         return const_cast<RenderView*>(toRenderView(this));
     603    ASSERT(!isTableCell());
     604    ASSERT(!isRenderView());
    612605
    613606    RenderObject* o = parent();
  • trunk/Source/WebCore/rendering/RenderObject.h

    r90833 r90882  
    572572
    573573    // returns the containing block level element for this element.
    574     RenderBlock* containingBlock() const;
     574    virtual RenderBlock* containingBlock() const;
    575575
    576576    // Convert the given local point to absolute coordinates
  • trunk/Source/WebCore/rendering/RenderTableCell.cpp

    r90675 r90882  
    320320}
    321321
     322RenderBlock* RenderTableCell::containingBlock() const
     323{
     324    if (parent() && section())
     325        return table();
     326    return 0;
     327}
     328
    322329// The following rules apply for resolving conflicts and figuring out which border
    323330// to use.
  • trunk/Source/WebCore/rendering/RenderTableCell.h

    r90675 r90882  
    138138    virtual bool isTableCell() const { return true; }
    139139
     140    virtual RenderBlock* containingBlock() const;
     141
    140142    virtual void willBeDestroyed();
    141143
  • trunk/Source/WebCore/rendering/RenderView.cpp

    r90734 r90882  
    258258}
    259259
     260RenderBlock* RenderView::containingBlock() const
     261{
     262    return const_cast<RenderView*>(this);
     263}
     264
    260265void RenderView::repaintViewRectangle(const IntRect& ur, bool immediate)
    261266{
  • trunk/Source/WebCore/rendering/RenderView.h

    r90734 r90882  
    171171    bool shouldRepaint(const IntRect& r) const;
    172172   
     173    virtual RenderBlock* containingBlock() const;
     174
    173175    // These functions may only be accessed by LayoutStateMaintainer.
    174176    bool pushLayoutState(RenderBox* renderer, const IntSize& offset, int pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
Note: See TracChangeset for help on using the changeset viewer.