Bug 1382964 - Part 1: Don't cache URLValueData::mMightHaveRef when in a traversal. r=xidorn
MozReview-Commit-ID: 2ucnu4vuaVg
--- 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
{