Bug 1452627: Fix nsStyleContentAttr stuff. r=bholley
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 12 Apr 2018 21:04:22 +0200
changeset 466668 2c051e8bfb3e463fe7e4c1b0f8a2e2e15f0e8a61
parent 466667 5c3c36ffacd8587cdd759270d94f80cc7187bebb
child 466669 57c0a4fc8ab6dfbb362c0102730a2d2cb1ba1ac1
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
bugs1452627
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 1452627: Fix nsStyleContentAttr stuff. r=bholley MozReview-Commit-ID: 4hi75VQcmkN
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -88,26 +88,16 @@ DefinitelyEqualImages(nsStyleImageReques
 
   if (!aRequest1 || !aRequest2) {
     return false;
   }
 
   return aRequest1->DefinitelyEquals(*aRequest2);
 }
 
-// A nullsafe wrapper for strcmp. We depend on null-safety.
-static int
-safe_strcmp(const char16_t* a, const char16_t* b)
-{
-  if (!a || !b) {
-    return (int)(a - b);
-  }
-  return NS_strcmp(a, b);
-}
-
 static bool AreShadowArraysEqual(nsCSSShadowArray* lhs, nsCSSShadowArray* rhs);
 
 // --------------------
 // nsStyleFont
 //
 nsStyleFont::nsStyleFont(const nsFont& aFont, const nsPresContext* aContext)
   : mFont(aFont)
   , mSize(nsStyleFont::ZoomText(aContext, mFont.size))
@@ -4137,16 +4127,17 @@ nsStyleVisibility::CalcDifference(const 
   return hint;
 }
 
 nsStyleContentData::~nsStyleContentData()
 {
   MOZ_COUNT_DTOR(nsStyleContentData);
 
   if (mType == eStyleContentType_Image) {
+    // FIXME(emilio): Is this needed now that URLs are not main thread only?
     NS_ReleaseOnMainThreadSystemGroup(
       "nsStyleContentData::mContent.mImage", dont_AddRef(mContent.mImage));
     mContent.mImage = nullptr;
   } else if (mType == eStyleContentType_Counter ||
              mType == eStyleContentType_Counters) {
     mContent.mCounters->Release();
   } else if (mType == eStyleContentType_String) {
     free(mContent.mString);
@@ -4156,27 +4147,35 @@ nsStyleContentData::~nsStyleContentData(
     MOZ_ASSERT(mContent.mString == nullptr, "Leaking due to missing case");
   }
 }
 
 nsStyleContentData::nsStyleContentData(const nsStyleContentData& aOther)
   : mType(aOther.mType)
 {
   MOZ_COUNT_CTOR(nsStyleContentData);
-  if (mType == eStyleContentType_Image) {
-    mContent.mImage = aOther.mContent.mImage;
-    mContent.mImage->AddRef();
-  } else if (mType == eStyleContentType_Counter ||
-             mType == eStyleContentType_Counters) {
-    mContent.mCounters = aOther.mContent.mCounters;
-    mContent.mCounters->AddRef();
-  } else if (aOther.mContent.mString) {
-    mContent.mString = NS_strdup(aOther.mContent.mString);
-  } else {
-    mContent.mString = nullptr;
+  switch (mType) {
+    case eStyleContentType_Image:
+      mContent.mImage = aOther.mContent.mImage;
+      mContent.mImage->AddRef();
+      break;
+    case eStyleContentType_Counter:
+    case eStyleContentType_Counters:
+      mContent.mCounters = aOther.mContent.mCounters;
+      mContent.mCounters->AddRef();
+      break;
+    case eStyleContentType_Attr:
+      mContent.mAttr = new nsStyleContentAttr(*mContent.mAttr);
+      break;
+    case eStyleContentType_String:
+      mContent.mString = NS_strdup(aOther.mContent.mString);
+      break;
+    default:
+      MOZ_ASSERT(!aOther.mContent.mString);
+      mContent.mString = nullptr;
   }
 }
 
 bool
 nsStyleContentData::
 CounterFunction::operator==(const CounterFunction& aOther) const
 {
   return mIdent == aOther.mIdent &&
@@ -4200,21 +4199,28 @@ bool
 nsStyleContentData::operator==(const nsStyleContentData& aOther) const
 {
   if (mType != aOther.mType) {
     return false;
   }
   if (mType == eStyleContentType_Image) {
     return DefinitelyEqualImages(mContent.mImage, aOther.mContent.mImage);
   }
+  if (mType == eStyleContentType_Attr) {
+    return *mContent.mAttr == *aOther.mContent.mAttr;
+  }
   if (mType == eStyleContentType_Counter ||
       mType == eStyleContentType_Counters) {
     return *mContent.mCounters == *aOther.mContent.mCounters;
   }
-  return safe_strcmp(mContent.mString, aOther.mContent.mString) == 0;
+  if (mType == eStyleContentType_String) {
+    return NS_strcmp(mContent.mString, aOther.mContent.mString) == 0;
+  }
+  MOZ_ASSERT(!mContent.mString && !aOther.mContent.mString);
+  return true;
 }
 
 void
 nsStyleContentData::Resolve(
   nsPresContext* aPresContext, const nsStyleContentData* aOldStyle)
 {
   switch (mType) {
     case eStyleContentType_Image:
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -2649,16 +2649,21 @@ enum nsStyleContentType {
   eStyleContentType_NoCloseQuote  = 43,
   eStyleContentType_AltContent    = 50,
   eStyleContentType_Uninitialized
 };
 
 struct nsStyleContentAttr {
   RefPtr<nsAtom> mName; // Non-null.
   RefPtr<nsAtom> mNamespaceURL; // May be null.
+
+  bool operator==(const nsStyleContentAttr& aOther) const
+  {
+    return mName == aOther.mName && mNamespaceURL == aOther.mNamespaceURL;
+  }
 };
 
 class nsStyleContentData
 {
 public:
   nsStyleContentData()
     : mType(eStyleContentType_Uninitialized)
   {