From 3125691c3f048e46bd3b41c61673e50fc2b58a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 2 Dec 2017 21:45:33 +0100 Subject: [PATCH] Bug 1422528: Inline and make stylo take the rare path for GetClasses directly. r=bz Servo already checks MayHaveClass. This should improve Gecko performance, too. MozReview-Commit-ID: KpVOVsKh6pe --HG-- extra : rebase_source : b0384546b1430915a18536b6ee8b29a936599873 --- dom/base/Element.cpp | 14 +++----------- dom/base/Element.h | 24 +++++++++++++++++++++--- layout/style/ServoBindings.cpp | 2 +- layout/style/ServoElementSnapshot.h | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index aef02f696dee..603a68ccbfdf 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -205,18 +205,10 @@ nsIContent::DoGetID() const } const nsAttrValue* -Element::DoGetClasses() const +Element::GetSVGAnimatedClass() const { - MOZ_ASSERT(MayHaveClass(), "Unexpected call"); - if (IsSVGElement()) { - const nsAttrValue* animClass = - static_cast(this)->GetAnimatedClassName(); - if (animClass) { - return animClass; - } - } - - return GetParsedAttr(nsGkAtoms::_class); + MOZ_ASSERT(MayHaveClass() && IsSVGElement(), "Unexpected call"); + return static_cast(this)->GetAnimatedClassName(); } NS_IMETHODIMP diff --git a/dom/base/Element.h b/dom/base/Element.h index fd933840faa5..6e2fe87ab965 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -900,6 +900,25 @@ public: return nullptr; } + /** + * Hook for implementing GetClasses. This should only be called if the + * ElementMayHaveClass flag is set. + * + * Public only because Servo needs to call it too, and it ensures the + * precondition before calling this. + */ + const nsAttrValue* DoGetClasses() const + { + MOZ_ASSERT(MayHaveClass(), "Unexpected call"); + if (IsSVGElement()) { + if (const nsAttrValue* value = GetSVGAnimatedClass()) { + return value; + } + } + + return GetParsedAttr(nsGkAtoms::_class); + } + #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override { @@ -1900,10 +1919,9 @@ protected: private: /** - * Hook for implementing GetClasses. This is guaranteed to only be - * called if the NODE_MAY_HAVE_CLASS flag is set. + * Slow path for DoGetClasses, this should only be called for SVG elements. */ - const nsAttrValue* DoGetClasses() const; + const nsAttrValue* GetSVGAnimatedClass() const; /** * Get this element's client area rect in app units. diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index e2ee890392ce..a58f03590102 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -1059,7 +1059,7 @@ template static uint32_t ClassOrClassList(Implementor* aElement, nsAtom** aClass, nsAtom*** aClassList) { - const nsAttrValue* attr = aElement->GetClasses(); + const nsAttrValue* attr = aElement->DoGetClasses(); if (!attr) { return 0; } diff --git a/layout/style/ServoElementSnapshot.h b/layout/style/ServoElementSnapshot.h index e67ebec8b9ce..8186183cf42a 100644 --- a/layout/style/ServoElementSnapshot.h +++ b/layout/style/ServoElementSnapshot.h @@ -151,7 +151,7 @@ public: return nullptr; } - const nsAttrValue* GetClasses() const + const nsAttrValue* DoGetClasses() const { MOZ_ASSERT(HasAttrs()); return &mClass;