Bug 1455492: Remove redundant ParseSheet arguments. r=bholley
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 20 Apr 2018 03:42:00 +0200
changeset 468475 c007f07170a5b3b377f45ab63c6c508ab0ebb58f
parent 468474 2398baa3198845ea904fcdee1f009dc11d0090bb
child 468476 046d0e259116679e2c4908cfa288e774dcddbf07
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1455492
milestone61.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 1455492: Remove redundant ParseSheet arguments. r=bholley For the async caller, pretty much everything can be extracted out of the loader / loadData. For the sync callers, we need to be a bit more careful because ReparseSheet tries to get its line number on its own. I changed the compat mode passed to the reparse stuff to be the document's one in this case, but that seems a bug fix. MozReview-Commit-ID: 2wi5HPRAlPi
dom/base/nsTreeSanitizer.cpp
layout/style/Loader.cpp
layout/style/ServoStyleSheet.cpp
layout/style/ServoStyleSheet.h
layout/style/nsLayoutStylesheetCache.cpp
--- a/dom/base/nsTreeSanitizer.cpp
+++ b/dom/base/nsTreeSanitizer.cpp
@@ -1093,19 +1093,20 @@ nsTreeSanitizer::SanitizeStyleSheet(cons
   // Create a sheet to hold the parsed CSS
   RefPtr<StyleSheet> sheet =
     new ServoStyleSheet(mozilla::css::eAuthorSheetFeatures,
                         CORS_NONE, aDocument->GetReferrerPolicy(),
                         SRIMetadata());
   sheet->SetURIs(aDocument->GetDocumentURI(), nullptr, aBaseURI);
   sheet->SetPrincipal(aDocument->NodePrincipal());
   sheet->AsServo()->ParseSheetSync(
-    aDocument->CSSLoader(), NS_ConvertUTF16toUTF8(aOriginal),
-    aDocument->GetDocumentURI(), aBaseURI, aDocument->NodePrincipal(),
-    /* aLoadData = */ nullptr, 0, aDocument->GetCompatibilityMode());
+    aDocument->CSSLoader(),
+    NS_ConvertUTF16toUTF8(aOriginal),
+    /* aLoadData = */ nullptr,
+    /* aLineNumber = */ 0);
   NS_ENSURE_SUCCESS(rv, true);
   // Mark the sheet as complete.
   MOZ_ASSERT(!sheet->HasForcedUniqueInner(),
              "should not get a forced unique inner during parsing");
   sheet->SetComplete();
   // Loop through all the rules found in the CSS text
   ErrorResult err;
   RefPtr<dom::CSSRuleList> rules =
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1630,26 +1630,17 @@ Loader::DoParseSheetServo(ServoStyleShee
                           bool aAllowAsync,
                           bool& aCompleted)
 {
   aLoadData->mIsBeingParsed = true;
 
   // Some cases, like inline style and UA stylesheets, need to be parsed
   // synchronously. The former may trigger child loads, the latter must not.
   if (aLoadData->mSyncLoad || !aAllowAsync) {
-    aSheet->ParseSheetSync(
-      this,
-      aBytes,
-      aSheet->GetSheetURI(),
-      aSheet->GetBaseURI(),
-      aSheet->Principal(),
-      aLoadData,
-      aLoadData->mLineNumber,
-      GetCompatibilityMode()
-    );
+    aSheet->ParseSheetSync(this, aBytes, aLoadData, aLoadData->mLineNumber);
     aLoadData->mIsBeingParsed = false;
 
     bool noPendingChildren = aLoadData->mPendingChildren == 0;
     MOZ_ASSERT_IF(aLoadData->mSyncLoad, noPendingChildren);
     if (noPendingChildren) {
       aCompleted = true;
       SheetComplete(aLoadData, NS_OK);
     }
@@ -1659,37 +1650,28 @@ Loader::DoParseSheetServo(ServoStyleShee
 
   // This parse does not need to be synchronous. \o/
   //
   // Note that we need to block onload because there may be no network requests
   // pending.
   BlockOnload();
   RefPtr<SheetLoadData> loadData = aLoadData;
   nsCOMPtr<nsISerialEventTarget> target = DispatchTarget();
-  aSheet->ParseSheet(
-    this,
-    aBytes,
-    aSheet->GetSheetURI(),
-    aSheet->GetBaseURI(),
-    aSheet->Principal(),
-    aLoadData,
-    aLoadData->mLineNumber,
-    GetCompatibilityMode()
-  )->Then(target, __func__,
-          [loadData](bool aDummy) {
-            MOZ_ASSERT(NS_IsMainThread());
-            loadData->mIsBeingParsed = false;
-            loadData->mLoader->UnblockOnload(/* aFireSync = */ false);
-            // If there are no child sheets outstanding, mark us as complete.
-            // Otherwise, the children are holding strong refs to the data and
-            // will call SheetComplete() on it when they complete.
-            if (loadData->mPendingChildren == 0) {
-              loadData->mLoader->SheetComplete(loadData, NS_OK);
-            }
-          }, [] { MOZ_CRASH("rejected parse promise"); }
+  aSheet->ParseSheet(this, aBytes, aLoadData)->Then(target, __func__,
+    [loadData](bool aDummy) {
+      MOZ_ASSERT(NS_IsMainThread());
+      loadData->mIsBeingParsed = false;
+      loadData->mLoader->UnblockOnload(/* aFireSync = */ false);
+      // If there are no child sheets outstanding, mark us as complete.
+      // Otherwise, the children are holding strong refs to the data and
+      // will call SheetComplete() on it when they complete.
+      if (loadData->mPendingChildren == 0) {
+        loadData->mLoader->SheetComplete(loadData, NS_OK);
+      }
+    }, [] { MOZ_CRASH("rejected parse promise"); }
   );
 
   return NS_OK;
 }
 
 /**
  * SheetComplete is the do-it-all cleanup function.  It removes the
  * load data from the "loading" hashtable, adds the sheet to the
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -229,49 +229,47 @@ AllowParallelParse(css::Loader* aLoader,
   }
 
   return true;
 }
 
 RefPtr<StyleSheetParsePromise>
 ServoStyleSheet::ParseSheet(css::Loader* aLoader,
                             const nsACString& aBytes,
-                            nsIURI* aSheetURI,
-                            nsIURI* aBaseURI,
-                            nsIPrincipal* aSheetPrincipal,
-                            css::SheetLoadData* aLoadData,
-                            uint32_t aLineNumber,
-                            nsCompatibility aCompatMode)
+                            css::SheetLoadData* aLoadData)
 {
+  MOZ_ASSERT(aLoader);
+  MOZ_ASSERT(aLoadData);
   MOZ_ASSERT(mParsePromise.IsEmpty());
   RefPtr<StyleSheetParsePromise> p = mParsePromise.Ensure(__func__);
-  Inner()->mURLData = new URLExtraData(aBaseURI, aSheetURI, aSheetPrincipal); // RefPtr
+  Inner()->mURLData =
+    new URLExtraData(GetBaseURI(), GetSheetURI(), Principal()); // RefPtr
 
-  if (!AllowParallelParse(aLoader, aSheetURI)) {
+  if (!AllowParallelParse(aLoader, GetSheetURI())) {
     RefPtr<RawServoStyleSheetContents> contents =
       Servo_StyleSheet_FromUTF8Bytes(aLoader,
                                      this,
                                      aLoadData,
                                      &aBytes,
                                      mParsingMode,
                                      Inner()->mURLData,
-                                     aLineNumber,
-                                     aCompatMode,
+                                     aLoadData->mLineNumber,
+                                     aLoader->GetCompatibilityMode(),
                                      /* reusable_sheets = */ nullptr)
       .Consume();
     FinishAsyncParse(contents.forget());
   } else {
     RefPtr<css::SheetLoadDataHolder> loadDataHolder =
       new css::SheetLoadDataHolder(__func__, aLoadData);
     Servo_StyleSheet_FromUTF8BytesAsync(loadDataHolder,
                                         Inner()->mURLData,
                                         &aBytes,
                                         mParsingMode,
-                                        aLineNumber,
-                                        aCompatMode);
+                                        aLoadData->mLineNumber,
+                                        aLoader->GetCompatibilityMode());
   }
 
   return Move(p);
 }
 
 void
 ServoStyleSheet::FinishAsyncParse(already_AddRefed<RawServoStyleSheetContents> aSheetContents)
 {
@@ -281,34 +279,32 @@ ServoStyleSheet::FinishAsyncParse(alread
   FinishParse();
   mParsePromise.Resolve(true, __func__);
 }
 
 
 void
 ServoStyleSheet::ParseSheetSync(css::Loader* aLoader,
                                 const nsACString& aBytes,
-                                nsIURI* aSheetURI,
-                                nsIURI* aBaseURI,
-                                nsIPrincipal* aSheetPrincipal,
                                 css::SheetLoadData* aLoadData,
                                 uint32_t aLineNumber,
-                                nsCompatibility aCompatMode,
                                 css::LoaderReusableStyleSheets* aReusableSheets)
 {
-  Inner()->mURLData = new URLExtraData(aBaseURI, aSheetURI, aSheetPrincipal); // RefPtr
+  nsCompatibility compatMode =
+    aLoader ? aLoader->GetCompatibilityMode() : eCompatibility_FullStandards;
 
+  Inner()->mURLData = new URLExtraData(GetBaseURI(), GetSheetURI(), Principal()); // RefPtr
   Inner()->mContents = Servo_StyleSheet_FromUTF8Bytes(aLoader,
                                                       this,
                                                       aLoadData,
                                                       &aBytes,
                                                       mParsingMode,
                                                       Inner()->mURLData,
                                                       aLineNumber,
-                                                      aCompatMode,
+                                                      compatMode,
                                                       aReusableSheets)
                          .Consume();
 
   FinishParse();
 }
 
 void
 ServoStyleSheet::FinishParse()
@@ -385,22 +381,18 @@ ServoStyleSheet::ReparseSheet(const nsAS
       RuleRemoved(*rule);
     }
   }
 
   DropRuleList();
 
   ParseSheetSync(loader,
                  NS_ConvertUTF16toUTF8(aInput),
-                 mInner->mSheetURI,
-                 mInner->mBaseURI,
-                 mInner->mPrincipal,
                  /* aLoadData = */ nullptr,
                  lineNumber,
-                 eCompatibility_FullStandards,
                  &reusableSheets);
   DidDirty();
 
   // Notify the stylesets about the new rules.
   {
     // Get the rule list (which will need to be regenerated after ParseSheet).
     ServoCSSRuleList* ruleList = GetCssRulesInternal();
     MOZ_ASSERT(ruleList);
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -89,38 +89,29 @@ public:
 
   bool HasRules() const;
 
   // Parses a stylesheet. The aLoadData argument corresponds to the
   // SheetLoadData for this stylesheet. It may be null in some cases.
   RefPtr<StyleSheetParsePromise>
   ParseSheet(css::Loader* aLoader,
              const nsACString& aBytes,
-             nsIURI* aSheetURI,
-             nsIURI* aBaseURI,
-             nsIPrincipal* aSheetPrincipal,
-             css::SheetLoadData* aLoadData,
-             uint32_t aLineNumber,
-             nsCompatibility aCompatMode);
+             css::SheetLoadData* aLoadData);
 
   // Common code that needs to be called after servo finishes parsing. This is
   // shared between the parallel and sequential paths.
   void FinishAsyncParse(already_AddRefed<RawServoStyleSheetContents> aSheetContents);
 
   // Similar to the above, but guarantees that parsing will be performed
   // synchronously.
   void
   ParseSheetSync(css::Loader* aLoader,
                  const nsACString& aBytes,
-                 nsIURI* aSheetURI,
-                 nsIURI* aBaseURI,
-                 nsIPrincipal* aSheetPrincipal,
                  css::SheetLoadData* aLoadData,
                  uint32_t aLineNumber,
-                 nsCompatibility aCompatMode,
                  css::LoaderReusableStyleSheets* aReusableSheets = nullptr);
 
   nsresult ReparseSheet(const nsAString& aInput);
 
   const RawServoStyleSheetContents* RawContents() const {
     return Inner()->mContents;
   }
 
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -883,20 +883,21 @@ nsLayoutStylesheetCache::BuildPreference
         NS_GET_R_G_B(focusBG));
   }
 
   NS_ASSERTION(sheetText.Length() <= kPreallocSize,
                "kPreallocSize should be big enough to build preference style "
                "sheet without reallocation");
 
   ServoStyleSheet* servoSheet = sheet->AsServo();
-  // NB: The pref sheet never has @import rules.
-  servoSheet->ParseSheetSync(nullptr, sheetText, uri, uri, nullptr,
-                             /* aLoadData = */ nullptr, 0,
-                             eCompatibility_FullStandards);
+  // NB: The pref sheet never has @import rules, thus no loader.
+  servoSheet->ParseSheetSync(nullptr,
+                             sheetText,
+                             /* aLoadData = */ nullptr,
+                             /* aLineNumber = */ 0);
 
 #undef NS_GET_R_G_B
 }
 
 mozilla::StaticRefPtr<nsLayoutStylesheetCache>
 nsLayoutStylesheetCache::gStyleCache;
 
 mozilla::StaticRefPtr<mozilla::css::Loader>