Commit e7f589e8 authored by antti@apple.com's avatar antti@apple.com

Make tests for renderer base types non-virtual

https://bugs.webkit.org/show_bug.cgi?id=122185

Reviewed by Dave Hyatt.

Make isRenderFoo() functions for commonly tested base types use bit flags instead of virtual calls.
This is faster and we have space in RenderElement.
        
These bits are not mutully exclusive. For testing leaf types we can add an enum.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9c586c50
2013-10-01 Antti Koivisto <antti@apple.com>
Make tests for renderer base types non-virtual
https://bugs.webkit.org/show_bug.cgi?id=122185
Reviewed by Dave Hyatt.
Make isRenderFoo() functions for commonly tested base types use bit flags instead of virtual calls.
This is faster and we have space in RenderElement.
These bits are not mutully exclusive. For testing leaf types we can add an enum.
2013-10-01 Ryosuke Niwa <rniwa@webkit.org>
Cleanup Document::dispatchFullScreenChangeOrErrorEvent
......@@ -149,8 +149,8 @@ private:
// -------------------------------------------------------------------------------------------------------
RenderBlock::RenderBlock(Element* element)
: RenderBox(element)
RenderBlock::RenderBlock(Element* element, unsigned baseTypeFlags)
: RenderBox(element, baseTypeFlags | RenderBlockFlag)
, m_lineHeight(-1)
, m_hasMarginBeforeQuirk(false)
, m_hasMarginAfterQuirk(false)
......
......@@ -98,7 +98,7 @@ public:
#endif
protected:
explicit RenderBlock(Element*);
explicit RenderBlock(Element*, unsigned baseTypeFlags);
virtual ~RenderBlock();
public:
......@@ -552,7 +552,6 @@ private:
virtual const char* renderName() const OVERRIDE;
virtual bool isRenderBlock() const OVERRIDE FINAL { return true; }
virtual bool isInlineBlockOrInlineTable() const OVERRIDE FINAL { return isInline() && isReplaced(); }
virtual bool canHaveChildren() const OVERRIDE { return true; }
......
......@@ -76,7 +76,7 @@ RenderBlockFlow::MarginInfo::MarginInfo(RenderBlockFlow* block, LayoutUnit befor
}
RenderBlockFlow::RenderBlockFlow(Element* element)
: RenderBlock(element)
: RenderBlock(element, RenderBlockFlowFlag)
{
COMPILE_ASSERT(sizeof(RenderBlockFlow::MarginInfo) == sizeof(SameSizeAsMarginInfo), MarginInfo_should_stay_small);
}
......
......@@ -31,9 +31,7 @@ class RenderBlockFlow : public RenderBlock {
public:
explicit RenderBlockFlow(Element*);
virtual ~RenderBlockFlow();
virtual bool isRenderBlockFlow() const OVERRIDE FINAL { return true; }
virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) OVERRIDE;
protected:
......
......@@ -95,8 +95,8 @@ static bool skipBodyBackground(const RenderBox* bodyElementRenderer)
&& (documentElementRenderer == bodyElementRenderer->parent());
}
RenderBox::RenderBox(Element* element)
: RenderBoxModelObject(element)
RenderBox::RenderBox(Element* element, unsigned baseTypeFlags)
: RenderBoxModelObject(element, baseTypeFlags)
, m_minPreferredLogicalWidth(-1)
, m_maxPreferredLogicalWidth(-1)
, m_inlineBoxWrapper(0)
......
......@@ -44,7 +44,7 @@ enum ShouldComputePreferred { ComputeActual, ComputePreferred };
class RenderBox : public RenderBoxModelObject {
public:
explicit RenderBox(Element*);
explicit RenderBox(Element*, unsigned baseTypeFlags);
virtual ~RenderBox();
// hasAutoZIndex only returns true if the element is positioned or a flex-item since
......
......@@ -159,8 +159,8 @@ bool RenderBoxModelObject::shouldPaintAtLowQuality(GraphicsContext* context, Ima
return view().imageQualityController().shouldPaintAtLowQuality(context, this, image, layer, size);
}
RenderBoxModelObject::RenderBoxModelObject(Element* element)
: RenderLayerModelObject(element)
RenderBoxModelObject::RenderBoxModelObject(Element* element, unsigned baseTypeFlags)
: RenderLayerModelObject(element, baseTypeFlags | RenderBoxModelObjectFlag)
{
}
......
......@@ -61,7 +61,7 @@ class StickyPositionViewportConstraints;
class RenderBoxModelObject : public RenderLayerModelObject {
public:
explicit RenderBoxModelObject(Element*);
explicit RenderBoxModelObject(Element*, unsigned baseTypeFlags);
virtual ~RenderBoxModelObject();
LayoutSize relativePositionOffset() const;
......@@ -309,7 +309,6 @@ public:
private:
LayoutUnit computedCSSPadding(Length) const;
virtual bool isBoxModelObject() const OVERRIDE FINAL { return true; }
virtual LayoutRect frameRectForStickyPositioning() const = 0;
......
......@@ -121,7 +121,7 @@ private:
};
RenderDeprecatedFlexibleBox::RenderDeprecatedFlexibleBox(Element& element)
: RenderBlock(&element)
: RenderBlock(&element, 0)
{
setChildrenInline(false); // All of our children must be block-level
m_stretchingChildren = false;
......
......@@ -64,8 +64,9 @@ namespace WebCore {
bool RenderElement::s_affectsParentBlock = false;
bool RenderElement::s_noLongerAffectsParentBlock = false;
RenderElement::RenderElement(Element* element)
RenderElement::RenderElement(Element* element, unsigned baseTypeFlags)
: RenderObject(element)
, m_baseTypeFlags(baseTypeFlags)
, m_ancestorLineBoxDirty(false)
, m_firstChild(nullptr)
, m_lastChild(nullptr)
......@@ -273,7 +274,7 @@ StyleDifference RenderElement::adjustStyleDifference(StyleDifference diff, unsig
// The answer to requiresLayer() for plugins, iframes, and canvas can change without the actual
// style changing, since it depends on whether we decide to composite these elements. When the
// layer status of one of these elements changes, we need to force a layout.
if (diff == StyleDifferenceEqual && style() && isLayerModelObject()) {
if (diff == StyleDifferenceEqual && style() && isRenderLayerModelObject()) {
if (hasLayer() != toRenderLayerModelObject(this)->requiresLayer())
diff = StyleDifferenceLayout;
}
......
......@@ -50,6 +50,14 @@ public:
RenderObject* firstChild() const { return m_firstChild; }
RenderObject* lastChild() const { return m_lastChild; }
// FIXME: Make these standalone and move to relevant files.
bool isRenderLayerModelObject() const;
bool isBoxModelObject() const;
bool isRenderBlock() const;
bool isRenderBlockFlow() const;
bool isRenderReplaced() const;
bool isRenderInline() const;
virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0) { return addChild(newChild, beforeChild); }
......@@ -86,7 +94,16 @@ public:
void setStyleInternal(PassRefPtr<RenderStyle> style) { m_style = style; }
protected:
explicit RenderElement(Element*);
enum BaseTypeFlags {
RenderLayerModelObjectFlag = 1 << 0,
RenderBoxModelObjectFlag = 1 << 1,
RenderInlineFlag = 1 << 2,
RenderReplacedFlag = 1 << 3,
RenderBlockFlag = 1 << 4,
RenderBlockFlowFlag = 1 << 5,
};
explicit RenderElement(Element*, unsigned baseTypeFlags);
bool layerCreationAllowedForSubtree() const;
......@@ -129,6 +146,7 @@ private:
StyleDifference adjustStyleDifference(StyleDifference, unsigned contextSensitiveProperties) const;
RenderStyle* cachedFirstLineStyle() const;
unsigned m_baseTypeFlags : 6;
bool m_ancestorLineBoxDirty : 1;
RenderObject* m_firstChild;
......@@ -164,6 +182,36 @@ inline LayoutUnit RenderElement::minimumValueForLength(const Length& length, Lay
return WebCore::minimumValueForLength(length, maximumValue, &view(), roundPercentages);
}
inline bool RenderElement::isRenderLayerModelObject() const
{
return m_baseTypeFlags & RenderLayerModelObjectFlag;
}
inline bool RenderElement::isBoxModelObject() const
{
return m_baseTypeFlags & RenderBoxModelObjectFlag;
}
inline bool RenderElement::isRenderBlock() const
{
return m_baseTypeFlags & RenderBlockFlag;
}
inline bool RenderElement::isRenderBlockFlow() const
{
return m_baseTypeFlags & RenderBlockFlowFlag;
}
inline bool RenderElement::isRenderReplaced() const
{
return m_baseTypeFlags & RenderReplacedFlag;
}
inline bool RenderElement::isRenderInline() const
{
return m_baseTypeFlags & RenderInlineFlag;
}
inline RenderElement& toRenderElement(RenderObject& object)
{
ASSERT_WITH_SECURITY_IMPLICATION(object.isRenderElement());
......@@ -192,6 +240,36 @@ inline const RenderElement* toRenderElement(const RenderObject* object)
void toRenderElement(const RenderElement*);
void toRenderElement(const RenderElement&);
inline bool RenderObject::isRenderLayerModelObject() const
{
return isRenderElement() && toRenderElement(this)->isRenderLayerModelObject();
}
inline bool RenderObject::isBoxModelObject() const
{
return isRenderElement() && toRenderElement(this)->isBoxModelObject();
}
inline bool RenderObject::isRenderBlock() const
{
return isRenderElement() && toRenderElement(this)->isRenderBlock();
}
inline bool RenderObject::isRenderBlockFlow() const
{
return isRenderElement() && toRenderElement(this)->isRenderBlockFlow();
}
inline bool RenderObject::isRenderReplaced() const
{
return isRenderElement() && toRenderElement(this)->isRenderReplaced();
}
inline bool RenderObject::isRenderInline() const
{
return isRenderElement() && toRenderElement(this)->isRenderInline();
}
inline RenderStyle* RenderObject::style() const
{
if (isText())
......
......@@ -124,7 +124,7 @@ struct RenderFlexibleBox::Violation {
RenderFlexibleBox::RenderFlexibleBox(Element* element)
: RenderBlock(element)
: RenderBlock(element, 0)
, m_orderIterator(this)
, m_numberOfInFlowChildrenOnFirstLine(-1)
{
......
......@@ -45,7 +45,7 @@
namespace WebCore {
RenderFrameSet::RenderFrameSet(HTMLFrameSetElement& frameSet)
: RenderBox(&frameSet)
: RenderBox(&frameSet, 0)
, m_isResizing(false)
, m_isChildResizing(false)
{
......
......@@ -127,7 +127,7 @@ private:
};
RenderGrid::RenderGrid(Element& element)
: RenderBlock(&element)
: RenderBlock(&element, 0)
{
// All of our children must be block level.
setChildrenInline(false);
......
......@@ -51,7 +51,7 @@ using namespace std;
namespace WebCore {
RenderInline::RenderInline(Element* element)
: RenderBoxModelObject(element)
: RenderBoxModelObject(element, RenderInlineFlag)
, m_alwaysCreateLineBoxes(false)
{
setChildrenInline(true);
......
......@@ -98,7 +98,6 @@ protected:
private:
virtual const char* renderName() const OVERRIDE;
virtual bool isRenderInline() const OVERRIDE FINAL { return true; }
virtual bool canHaveChildren() const OVERRIDE FINAL { return true; }
LayoutRect culledInlineVisualOverflowBoundingBox() const;
......
......@@ -37,8 +37,8 @@ bool RenderLayerModelObject::s_hadLayer = false;
bool RenderLayerModelObject::s_hadTransform = false;
bool RenderLayerModelObject::s_layerWasSelfPainting = false;
RenderLayerModelObject::RenderLayerModelObject(Element* element)
: RenderElement(element)
RenderLayerModelObject::RenderLayerModelObject(Element* element, unsigned baseTypeFlags)
: RenderElement(element, baseTypeFlags | RenderLayerModelObjectFlag)
, m_layer(0)
{
}
......
......@@ -31,7 +31,7 @@ class RenderLayer;
class RenderLayerModelObject : public RenderElement {
public:
explicit RenderLayerModelObject(Element*);
explicit RenderLayerModelObject(Element*, unsigned baseTypeFlags);
virtual ~RenderLayerModelObject();
// Called by RenderObject::willBeDestroyed() and is the only way layers should ever be destroyed
......@@ -57,8 +57,6 @@ protected:
virtual void willBeDestroyed() OVERRIDE;
private:
virtual bool isLayerModelObject() const OVERRIDE FINAL { return true; }
RenderLayer* m_layer;
// Used to store state between styleWillChange and styleDidChange
......@@ -70,13 +68,13 @@ private:
inline RenderLayerModelObject* toRenderLayerModelObject(RenderObject* object)
{
ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isLayerModelObject());
ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderLayerModelObject());
return static_cast<RenderLayerModelObject*>(object);
}
inline const RenderLayerModelObject* toRenderLayerModelObject(const RenderObject* object)
{
ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isLayerModelObject());
ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderLayerModelObject());
return static_cast<const RenderLayerModelObject*>(object);
}
......
......@@ -33,7 +33,7 @@ namespace WebCore {
static const int invalidLineHeight = -1;
RenderLineBreak::RenderLineBreak(HTMLElement& element)
: RenderBoxModelObject(&element)
: RenderBoxModelObject(&element, 0)
, m_inlineBoxWrapper(nullptr)
, m_cachedLineHeight(invalidLineHeight)
, m_isWBR(element.hasTagName(HTMLNames::wbrTag))
......
......@@ -1118,7 +1118,7 @@ String listMarkerText(EListStyleType type, int value)
}
RenderListMarker::RenderListMarker(RenderListItem& listItem)
: RenderBox(0)
: RenderBox(nullptr, 0)
, m_listItem(listItem)
{
// init RenderObject attributes
......
......@@ -303,7 +303,13 @@ public:
bool isPseudoElement() const { return node() && node()->isPseudoElement(); }
bool isRenderElement() const { return !isText(); }
virtual bool isBoxModelObject() const { return false; }
bool isRenderReplaced() const;
bool isBoxModelObject() const;
bool isRenderBlock() const;
bool isRenderBlockFlow() const;
bool isRenderInline() const;
bool isRenderLayerModelObject() const;
virtual bool isCounter() const { return false; }
virtual bool isQuote() const { return false; }
......@@ -317,7 +323,6 @@ public:
virtual bool isFrameSet() const { return false; }
virtual bool isImage() const { return false; }
virtual bool isInlineBlockOrInlineTable() const { return false; }
virtual bool isLayerModelObject() const { return false; }
virtual bool isListBox() const { return false; }
virtual bool isListItem() const { return false; }
virtual bool isListMarker() const { return false; }
......@@ -330,15 +335,11 @@ public:
#if ENABLE(PROGRESS_ELEMENT)
virtual bool isProgress() const { return false; }
#endif
virtual bool isRenderBlock() const { return false; }
virtual bool isRenderBlockFlow() const { return false; }
virtual bool isRenderSVGBlock() const { return false; };
virtual bool isRenderButton() const { return false; }
virtual bool isRenderIFrame() const { return false; }
virtual bool isRenderImage() const { return false; }
virtual bool isRenderInline() const { return false; }
virtual bool isRenderRegion() const { return false; }
virtual bool isRenderReplaced() const { return false; }
virtual bool isReplica() const { return false; }
virtual bool isRuby() const { return false; }
......
......@@ -43,14 +43,14 @@ const int cDefaultWidth = 300;
const int cDefaultHeight = 150;
RenderReplaced::RenderReplaced(Element* element)
: RenderBox(element)
: RenderBox(element, RenderReplacedFlag)
, m_intrinsicSize(cDefaultWidth, cDefaultHeight)
{
setReplaced(true);
}
RenderReplaced::RenderReplaced(Element* element, const LayoutSize& intrinsicSize)
: RenderBox(element)
: RenderBox(element, RenderReplacedFlag)
, m_intrinsicSize(intrinsicSize)
{
setReplaced(true);
......
......@@ -41,8 +41,6 @@ public:
bool hasReplacedLogicalHeight() const;
protected:
virtual bool isRenderReplaced() const OVERRIDE FINAL { return true; }
virtual void willBeDestroyed();
virtual void layout();
......
......@@ -35,7 +35,7 @@
namespace WebCore {
RenderReplica::RenderReplica()
: RenderBox(0)
: RenderBox(nullptr, 0)
{
// This is a hack. Replicas are synthetic, and don't pick up the attributes of the
// renderers being replicated, so they always report that they are inline, non-replaced.
......
......@@ -37,7 +37,7 @@ using namespace std;
namespace WebCore {
RenderScrollbarPart::RenderScrollbarPart(RenderScrollbar* scrollbar, ScrollbarPart part)
: RenderBlock(0)
: RenderBlock(nullptr, 0)
, m_scrollbar(scrollbar)
, m_part(part)
{
......
......@@ -51,7 +51,7 @@ namespace WebCore {
using namespace HTMLNames;
RenderTable::RenderTable(Element* element)
: RenderBlock(element)
: RenderBlock(element, 0)
, m_head(0)
, m_foot(0)
, m_firstBody(0)
......
......@@ -36,7 +36,7 @@ namespace WebCore {
using namespace HTMLNames;
RenderTableCol::RenderTableCol(Element& element)
: RenderBox(&element)
: RenderBox(&element, 0)
, m_span(1)
{
// init RenderObject attributes
......
......@@ -39,7 +39,7 @@ namespace WebCore {
using namespace HTMLNames;
RenderTableRow::RenderTableRow(Element* element)
: RenderBox(element)
: RenderBox(element, 0)
, m_rowIndex(unsetRowIndex)
{
// init RenderObject attributes
......
......@@ -85,7 +85,7 @@ static inline void updateLogicalHeightForCell(RenderTableSection::RowStruct& row
RenderTableSection::RenderTableSection(Element* element)
: RenderBox(element)
: RenderBox(element, 0)
, m_cCol(0)
, m_cRow(0)
, m_outerBorderStart(0)
......
......@@ -34,7 +34,7 @@ namespace WebCore {
using namespace SVGNames;
RenderSVGGradientStop::RenderSVGGradientStop(SVGStopElement* element)
: RenderElement(element)
: RenderElement(element, 0)
{
}
......
......@@ -43,7 +43,7 @@
namespace WebCore {
RenderSVGModelObject::RenderSVGModelObject(SVGElement& element)
: RenderElement(&element)
: RenderElement(&element, 0)
, m_hasSVGShadow(false)
{
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment