Bug 1304302 part 5 - Make StyleSheet::As{Gecko,Servo} return pointer instead of reference. r=heycam
authorXidorn Quan <me@upsuper.org>
Mon, 26 Sep 2016 22:03:25 +1000
changeset 315279 ec5b85b4507c43860d788e240983981e3da86e44
parent 315278 3c390d4c86a298f05764285f988f230b58535c65
child 315280 203b90fcacdf0092fc0867b7afeaf3c424745eae
push id30747
push usercbook@mozilla.com
push dateTue, 27 Sep 2016 09:22:00 +0000
treeherdermozilla-central@66a77b9bfe5d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1304302
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1304302 part 5 - Make StyleSheet::As{Gecko,Servo} return pointer instead of reference. r=heycam To match the behavior of StyleSheetHandle so that we can simply replace uses of StyleSheetHandle with StyleSheet* in later patch. MozReview-Commit-ID: LfGKrUmzC4h
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
layout/style/StyleSheetInlines.h
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -53,17 +53,18 @@ bool
 StyleSheet::IsComplete() const
 {
   return SheetInfo().mComplete;
 }
 
 void
 StyleSheet::SetComplete()
 {
-  NS_ASSERTION(!IsGecko() || !AsGecko().mDirty, "Can't set a dirty sheet complete!");
+  NS_ASSERTION(!IsGecko() || !AsGecko()->mDirty,
+               "Can't set a dirty sheet complete!");
   SheetInfo().mComplete = true;
   if (mDocument && !mDisabled) {
     // Let the document know
     mDocument->BeginUpdate(UPDATE_STYLE);
     mDocument->SetStyleSheetApplicableState(AsHandle(), true);
     mDocument->EndUpdate(UPDATE_STYLE);
   }
 
@@ -74,14 +75,14 @@ StyleSheet::SetComplete()
     shadowRoot->StyleSheetChanged();
   }
 }
 
 StyleSheetInfo&
 StyleSheet::SheetInfo()
 {
   if (IsServo()) {
-    return AsServo();
+    return *AsServo();
   }
-  return *AsGecko().mInner;
+  return *AsGecko()->mInner;
 }
 
 } // namespace mozilla
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -62,21 +62,21 @@ public:
     return mType == StyleBackendType::Servo;
 #else
     return false;
 #endif
   }
 
   // Only safe to call if the caller has verified that that |this| is of the
   // correct type.
-  inline CSSStyleSheet& AsGecko();
-  inline ServoStyleSheet& AsServo();
+  inline CSSStyleSheet* AsGecko();
+  inline ServoStyleSheet* AsServo();
   inline StyleSheetHandle AsHandle();
-  inline const CSSStyleSheet& AsGecko() const;
-  inline const ServoStyleSheet& AsServo() const;
+  inline const CSSStyleSheet* AsGecko() const;
+  inline const ServoStyleSheet* AsServo() const;
 
   inline MozExternalRefCountType AddRef();
   inline MozExternalRefCountType Release();
 
   // Whether the sheet is for an inline <style> element.
   inline bool IsInline() const;
 
   inline nsIURI* GetSheetURI() const;
--- a/layout/style/StyleSheetInlines.h
+++ b/layout/style/StyleSheetInlines.h
@@ -8,64 +8,64 @@
 #define mozilla_StyleSheetInlines_h
 
 #include "mozilla/TypeTraits.h"
 #include "mozilla/ServoStyleSheet.h"
 #include "mozilla/CSSStyleSheet.h"
 
 namespace mozilla {
 
-CSSStyleSheet&
+CSSStyleSheet*
 StyleSheet::AsGecko()
 {
   MOZ_ASSERT(IsGecko());
-  return *static_cast<CSSStyleSheet*>(this);
+  return static_cast<CSSStyleSheet*>(this);
 }
 
-ServoStyleSheet&
+ServoStyleSheet*
 StyleSheet::AsServo()
 {
   MOZ_ASSERT(IsServo());
-  return *static_cast<ServoStyleSheet*>(this);
+  return static_cast<ServoStyleSheet*>(this);
 }
 
 StyleSheetHandle
 StyleSheet::AsHandle()
 {
   if (IsServo()) {
-    return &AsServo();
+    return AsServo();
   }
-  return &AsGecko();
+  return AsGecko();
 }
 
-const CSSStyleSheet&
+const CSSStyleSheet*
 StyleSheet::AsGecko() const
 {
   MOZ_ASSERT(IsGecko());
-  return *static_cast<const CSSStyleSheet*>(this);
+  return static_cast<const CSSStyleSheet*>(this);
 }
 
-const ServoStyleSheet&
+const ServoStyleSheet*
 StyleSheet::AsServo() const
 {
   MOZ_ASSERT(IsServo());
-  return *static_cast<const ServoStyleSheet*>(this);
+  return static_cast<const ServoStyleSheet*>(this);
 }
 
 #define FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \
   static_assert(!IsSame<decltype(&StyleSheet::method_), \
                         decltype(&CSSStyleSheet::method_)>::value, \
                 "CSSStyleSheet should define its own " #method_); \
   static_assert(!IsSame<decltype(&StyleSheet::method_), \
                         decltype(&ServoStyleSheet::method_)>::value, \
                 "ServoStyleSheet should define its own " #method_); \
   if (IsServo()) { \
-    return AsServo().method_ servoargs_; \
+    return AsServo()->method_ servoargs_; \
   } \
-  return AsGecko().method_ geckoargs_;
+  return AsGecko()->method_ geckoargs_;
 
 #define FORWARD(method_, args_) FORWARD_CONCRETE(method_, args_, args_)
 
 MozExternalRefCountType
 StyleSheet::AddRef()
 {
   FORWARD(AddRef, ())
 }
@@ -135,17 +135,17 @@ StyleSheet*
 StyleSheet::GetParentSheet() const
 {
   FORWARD(GetParentSheet, ())
 }
 
 void
 StyleSheet::AppendStyleSheet(StyleSheet* aSheet)
 {
-  FORWARD_CONCRETE(AppendStyleSheet, (&aSheet->AsGecko()), (&aSheet->AsServo()))
+  FORWARD_CONCRETE(AppendStyleSheet, (aSheet->AsGecko()), (aSheet->AsServo()))
 }
 
 nsIPrincipal*
 StyleSheet::Principal() const
 {
   return SheetInfo().mPrincipal;
 }