Bug 1382964 - Part 1: Don't cache URLValueData::mMightHaveRef when in a traversal. r=xidorn
authorCameron McCormack <cam@mcc.id.au>
Fri, 21 Jul 2017 16:34:20 +0800
changeset 419162 0fed5a7719c1f524c28a80f699d7494d7af5d782
parent 419082 2772b4c382ff93d4218f091f31c53b36e5af657a
child 419163 65fb1f76ed5be8feefc81390eeb7ef7f36cbcca4
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1382964
milestone56.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 1382964 - Part 1: Don't cache URLValueData::mMightHaveRef when in a traversal. r=xidorn MozReview-Commit-ID: 2ucnu4vuaVg
layout/style/nsCSSValue.cpp
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -2887,41 +2887,45 @@ css::URLValueData::IsLocalRef() const
   }
 
   return mIsLocalRef.value();
 }
 
 bool
 css::URLValueData::HasRef() const
 {
+  bool result = false;
+
   if (IsLocalRef()) {
-    return true;
-  }
-
-  nsIURI* uri = GetURI();
-  if (!uri) {
-    return false;
+    result = true;
+  } else {
+    if (nsIURI* uri = GetURI()) {
+      nsAutoCString ref;
+      nsresult rv = uri->GetRef(ref);
+      if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
+        result = true;
+      }
+    }
   }
 
-  nsAutoCString ref;
-  nsresult rv = uri->GetRef(ref);
-  if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
-    return true;
-  }
-
-  return false;
+  mMightHaveRef = Some(result);
+
+  return result;
 }
 
 bool
 css::URLValueData::MightHaveRef() const
 {
   if (mMightHaveRef.isNothing()) {
-    // ::MightHaveRef is O(N), use it only use it only when MightHaveRef is
-    // called.
-    mMightHaveRef.emplace(::MightHaveRef(mString));
+    bool result = ::MightHaveRef(mString);
+    if (!ServoStyleSet::IsInServoTraversal()) {
+      // Can only cache the result if we're not on a style worker thread.
+      mMightHaveRef.emplace(result);
+    }
+    return result;
   }
 
   return mMightHaveRef.value();
 }
 
 already_AddRefed<nsIURI>
 css::URLValueData::ResolveLocalRef(nsIURI* aURI) const
 {