Commit 79d683e3 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Make manual isSVG*Element() helpers as efficient as the generated ones

Make manual isSVG*Element() helpers as efficient as the generated ones by
introducing a DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION() macro, similarly
to the DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(). This new macro is
used instead of DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION() for SVG types so
that the isSVG*Element() helpers leverage the faster
SVGElement::hasTagName(SVGQualifiedName) when possible (i.e. when the input
is an SVGElement*).

This is a follow-up to:
https://src.chromium.org/viewvc/blink?view=rev&revision=178540

R=pdr@chromium.org, abarth@chromium.org

Review URL: https://codereview.chromium.org/403343005

git-svn-id: svn://svn.chromium.org/blink/trunk@178580 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent cf2f942a
...@@ -37,7 +37,6 @@ namespace blink { ...@@ -37,7 +37,6 @@ namespace blink {
SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document& document) SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document& document)
: SVGAnimationElement(tagName, document) : SVGAnimationElement(tagName, document)
{ {
ASSERT(isSVGAnimateElement(*this));
ScriptWrappable::init(this); ScriptWrappable::init(this);
} }
......
...@@ -73,14 +73,14 @@ private: ...@@ -73,14 +73,14 @@ private:
OwnPtrWillBeMember<SVGAnimatedTypeAnimator> m_animator; OwnPtrWillBeMember<SVGAnimatedTypeAnimator> m_animator;
}; };
inline bool isSVGAnimateElement(const Node& node) inline bool isSVGAnimateElement(const SVGElement& element)
{ {
return node.hasTagName(SVGNames::animateTag) return element.hasTagName(SVGNames::animateTag)
|| node.hasTagName(SVGNames::animateTransformTag) || element.hasTagName(SVGNames::animateTransformTag)
|| node.hasTagName(SVGNames::setTag); || element.hasTagName(SVGNames::setTag);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGAnimateElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGAnimateElement);
} // namespace blink } // namespace blink
......
...@@ -271,6 +271,18 @@ inline bool Node::hasTagName(const SVGQualifiedName& name) const ...@@ -271,6 +271,18 @@ inline bool Node::hasTagName(const SVGQualifiedName& name) const
return isSVGElement() && toSVGElement(*this).hasTagName(name); return isSVGElement() && toSVGElement(*this).hasTagName(name);
} }
// This requires isSVG*Element(const SVGElement&).
#define DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
inline bool is##thisType(const thisType* element); \
inline bool is##thisType(const thisType& element); \
inline bool is##thisType(const SVGElement* element) { return element && is##thisType(*element); } \
inline bool is##thisType(const Node& node) { return node.isSVGElement() ? is##thisType(toSVGElement(node)) : false; } \
inline bool is##thisType(const Node* node) { return node && is##thisType(*node); } \
template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { return is##thisType(node.get()); } \
template<typename T> inline bool is##thisType(const RefPtr<T>& node) { return is##thisType(node.get()); } \
template <> inline bool isElementOfType<const thisType>(const SVGElement& element) { return is##thisType(element); } \
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType)
} }
#include "core/SVGElementTypeHelpers.h" #include "core/SVGElementTypeHelpers.h"
......
...@@ -83,12 +83,12 @@ private: ...@@ -83,12 +83,12 @@ private:
RefPtr<SVGAnimatedNumber> m_limitingConeAngle; RefPtr<SVGAnimatedNumber> m_limitingConeAngle;
}; };
inline bool isSVGFELightElement(const Node& node) inline bool isSVGFELightElement(const SVGElement& element)
{ {
return node.hasTagName(SVGNames::feDistantLightTag) || node.hasTagName(SVGNames::fePointLightTag) || node.hasTagName(SVGNames::feSpotLightTag); return element.hasTagName(SVGNames::feDistantLightTag) || element.hasTagName(SVGNames::fePointLightTag) || element.hasTagName(SVGNames::feSpotLightTag);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGFELightElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGFELightElement);
} // namespace blink } // namespace blink
......
...@@ -73,12 +73,12 @@ private: ...@@ -73,12 +73,12 @@ private:
RefPtr<SVGAnimatedEnumeration<SVGUnitTypes::SVGUnitType> > m_gradientUnits; RefPtr<SVGAnimatedEnumeration<SVGUnitTypes::SVGUnitType> > m_gradientUnits;
}; };
inline bool isSVGGradientElement(const Node& node) inline bool isSVGGradientElement(const SVGElement& element)
{ {
return node.hasTagName(SVGNames::radialGradientTag) || node.hasTagName(SVGNames::linearGradientTag); return element.hasTagName(SVGNames::radialGradientTag) || element.hasTagName(SVGNames::linearGradientTag);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGGradientElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGGradientElement);
} // namespace blink } // namespace blink
......
...@@ -86,12 +86,12 @@ private: ...@@ -86,12 +86,12 @@ private:
OwnPtr<AffineTransform> m_supplementalTransform; OwnPtr<AffineTransform> m_supplementalTransform;
}; };
inline bool isSVGGraphicsElement(const Node& node) inline bool isSVGGraphicsElement(const SVGElement& element)
{ {
return node.isSVGElement() && toSVGElement(node).isSVGGraphicsElement(); return element.isSVGGraphicsElement();
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGGraphicsElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGGraphicsElement);
} // namespace blink } // namespace blink
......
...@@ -48,12 +48,12 @@ private: ...@@ -48,12 +48,12 @@ private:
}; };
inline bool isSVGPolyElement(const Node& node) inline bool isSVGPolyElement(const SVGElement& element)
{ {
return node.hasTagName(SVGNames::polygonTag) || node.hasTagName(SVGNames::polylineTag); return element.hasTagName(SVGNames::polygonTag) || element.hasTagName(SVGNames::polylineTag);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGPolyElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGPolyElement);
} // namespace blink } // namespace blink
......
...@@ -82,12 +82,12 @@ private: ...@@ -82,12 +82,12 @@ private:
RefPtr<SVGAnimatedEnumeration<SVGLengthAdjustType> > m_lengthAdjust; RefPtr<SVGAnimatedEnumeration<SVGLengthAdjustType> > m_lengthAdjust;
}; };
inline bool isSVGTextContentElement(const Node& node) inline bool isSVGTextContentElement(const SVGElement& element)
{ {
return node.isSVGElement() && toSVGElement(node).isTextContent(); return element.isTextContent();
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGTextContentElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGTextContentElement);
} // namespace blink } // namespace blink
......
...@@ -53,12 +53,12 @@ protected: ...@@ -53,12 +53,12 @@ protected:
RefPtr<SVGAnimatedNumberList> m_rotate; RefPtr<SVGAnimatedNumberList> m_rotate;
}; };
inline bool isSVGTextPositioningElement(const Node& node) inline bool isSVGTextPositioningElement(const SVGElement& element)
{ {
return node.isSVGElement() && toSVGElement(node).isTextPositioning(); return element.isTextPositioning();
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGTextPositioningElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGTextPositioningElement);
} // namespace blink } // namespace blink
......
...@@ -274,13 +274,13 @@ private: ...@@ -274,13 +274,13 @@ private:
friend class ConditionEventListener; friend class ConditionEventListener;
}; };
inline bool isSVGSMILElement(const Node& node) inline bool isSVGSMILElement(const SVGElement& element)
{ {
return node.hasTagName(SVGNames::setTag) || node.hasTagName(SVGNames::animateTag) || node.hasTagName(SVGNames::animateMotionTag) return element.hasTagName(SVGNames::setTag) || element.hasTagName(SVGNames::animateTag) || element.hasTagName(SVGNames::animateMotionTag)
|| node.hasTagName(SVGNames::animateTransformTag) || node.hasTagName((SVGNames::discardTag)); || element.hasTagName(SVGNames::animateTransformTag) || element.hasTagName((SVGNames::discardTag));
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGSMILElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGSMILElement);
} }
......
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