Bug 1382964 - Part 1: Don't cache URLValueData::mMightHaveRef when in a traversal. r=xidorn draft
authorCameron McCormack <cam@mcc.id.au>
Fri, 21 Jul 2017 16:34:20 +0800
changeset 613888 5c61f935a91426078ead5c80a014874cb9723a69
parent 613568 057d626fc5e1afbf4086eb9400ebb3718a4cabca
child 613889 886f354f9b8e1e1ef303513faebecf8c44a4bfc6
push id69872
push userbmo:cam@mcc.id.au
push dateSun, 23 Jul 2017 07:51:39 +0000
reviewersxidorn
bugs1382964
milestone56.0a1
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
 {