Backed out changeset 2a7dd15c8206 (bug 1404897)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Wed, 04 Oct 2017 11:24:31 +0200
changeset 427048 e63b7088a1a5365af741c0787f89e5a1320cb126
parent 427047 ecaeee74172394694d028d60fa365a153101ee7b
child 427049 084da44465b0fa68d08e09fe99fb91dbdccfe248
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
bugs1404897
milestone58.0a1
backs out2a7dd15c82061aeef1aa9b174058748e80f20390
Backed out changeset 2a7dd15c8206 (bug 1404897)
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
dom/base/nsINode.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1401,49 +1401,23 @@ nsIDocument::SelectorCache::SelectorCach
       1000, "nsIDocument::SelectorCache", aEventTarget)
 { }
 
 nsIDocument::SelectorCache::~SelectorCache()
 {
   AgeAllGenerations();
 }
 
-void
-nsIDocument::SelectorCache::SelectorList::Reset()
-{
-  if (mIsServo) {
-    if (mServo) {
-      Servo_SelectorList_Drop(mServo);
-      mServo = nullptr;
-    }
-  } else {
-    if (mGecko) {
-      delete mGecko;
-      mGecko = nullptr;
-    }
-  }
-}
-
 // CacheList takes ownership of aSelectorList.
 void nsIDocument::SelectorCache::CacheList(const nsAString& aSelector,
-                                           mozilla::UniquePtr<nsCSSSelectorList>&& aSelectorList)
+                                           nsCSSSelectorList* aSelectorList)
 {
   MOZ_ASSERT(NS_IsMainThread());
   SelectorCacheKey* key = new SelectorCacheKey(aSelector);
-  mTable.Put(key->mKey, SelectorList(Move(aSelectorList)));
-  AddObject(key);
-}
-
-void nsIDocument::SelectorCache::CacheList(
-  const nsAString& aSelector,
-  UniquePtr<RawServoSelectorList>&& aSelectorList)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  SelectorCacheKey* key = new SelectorCacheKey(aSelector);
-  mTable.Put(key->mKey, SelectorList(Move(aSelectorList)));
+  mTable.Put(key->mKey, aSelectorList);
   AddObject(key);
 }
 
 void nsIDocument::SelectorCache::NotifyExpired(SelectorCacheKey* aSelector)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aSelector);
 
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -32,17 +32,16 @@
 #include "nsContentListDeclarations.h"
 #include "nsExpirationTracker.h"
 #include "nsClassHashtable.h"
 #include "mozilla/CORSMode.h"
 #include "mozilla/dom/DispatcherTrait.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/NotNull.h"
 #include "mozilla/SegmentedVector.h"
-#include "mozilla/ServoBindingTypes.h"
 #include "mozilla/StyleBackendType.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
 #include <bitset>                        // for member
 
 #ifdef MOZILLA_INTERNAL_API
 #include "mozilla/dom/DocumentBinding.h"
@@ -1144,116 +1143,37 @@ private:
 
   class SelectorCacheKeyDeleter;
 
 public:
   class SelectorCache final
     : public nsExpirationTracker<SelectorCacheKey, 4>
   {
     public:
-      class SelectorList
-      {
-      public:
-        SelectorList()
-          : mIsServo(false)
-          , mGecko(nullptr)
-        {}
-
-        SelectorList(SelectorList&& aOther)
-        {
-          *this = mozilla::Move(aOther);
-        }
-
-        SelectorList& operator=(SelectorList&& aOther)
-        {
-          Reset();
-          mIsServo = aOther.mIsServo;
-          if (mIsServo) {
-            mServo = aOther.mServo;
-            aOther.mServo = nullptr;
-          } else {
-            mGecko = aOther.mGecko;
-            aOther.mGecko = nullptr;
-          }
-          return *this;
-        }
-
-        SelectorList(const SelectorList& aOther) = delete;
-
-        SelectorList(mozilla::UniquePtr<RawServoSelectorList>&& aList)
-          : mIsServo(true)
-          , mServo(aList.release())
-        {}
-
-        SelectorList(mozilla::UniquePtr<nsCSSSelectorList>&& aList)
-          : mIsServo(false)
-          , mGecko(aList.release())
-        {}
-
-        ~SelectorList() {
-          Reset();
-        }
-
-        bool IsServo() const { return mIsServo; }
-        bool IsGecko() const { return !IsServo(); }
-
-        explicit operator bool() const
-        {
-          return IsServo() ? !!AsServo() : !!AsGecko();
-        }
-
-        nsCSSSelectorList* AsGecko() const
-        {
-          MOZ_ASSERT(IsGecko());
-          return mGecko;
-        }
-
-        RawServoSelectorList* AsServo() const
-        {
-          MOZ_ASSERT(IsServo());
-          return mServo;
-        }
-
-      private:
-        void Reset();
-
-        bool mIsServo;
-
-        union {
-          nsCSSSelectorList* mGecko;
-          RawServoSelectorList* mServo;
-        };
-      };
-
       explicit SelectorCache(nsIEventTarget* aEventTarget);
 
       // CacheList takes ownership of aSelectorList.
-      void CacheList(const nsAString& aSelector,
-                     mozilla::UniquePtr<nsCSSSelectorList>&& aSelectorList);
-      void CacheList(const nsAString& aSelector,
-                     mozilla::UniquePtr<RawServoSelectorList>&& aSelectorList);
+      void CacheList(const nsAString& aSelector, nsCSSSelectorList* aSelectorList);
 
       virtual void NotifyExpired(SelectorCacheKey* aSelector) override;
 
       // We do not call MarkUsed because it would just slow down lookups and
       // because we're OK expiring things after a few seconds even if they're
       // being used.  Returns whether we actually had an entry for aSelector.
-      //
-      // If we have an entry and the selector list returned has a null
-      // nsCSSSelectorList*/RawServoSelectorList*, that indicates that aSelector
+      // If we have an entry and *aList is null, that indicates that aSelector
       // has already been parsed and is not a syntactically valid selector.
-      SelectorList* GetList(const nsAString& aSelector)
+      bool GetList(const nsAString& aSelector, nsCSSSelectorList** aList)
       {
-        return mTable.GetValue(aSelector);
+        return mTable.Get(aSelector, aList);
       }
 
       ~SelectorCache();
 
     private:
-      nsDataHashtable<nsStringHashKey, SelectorList> mTable;
+      nsClassHashtable<nsStringHashKey, nsCSSSelectorList> mTable;
   };
 
   SelectorCache& GetSelectorCache() {
     if (!mSelectorCache) {
       mSelectorCache =
         new SelectorCache(EventTargetFor(mozilla::TaskCategory::Other));
     }
     return *mSelectorCache;
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -2677,33 +2677,31 @@ nsINode::Length() const
 }
 
 nsCSSSelectorList*
 nsINode::ParseSelectorList(const nsAString& aSelectorString,
                            ErrorResult& aRv)
 {
   nsIDocument* doc = OwnerDoc();
   nsIDocument::SelectorCache& cache = doc->GetSelectorCache();
-  nsIDocument::SelectorCache::SelectorList* list =
-    cache.GetList(aSelectorString);
-  if (list) {
-    if (!*list) {
+  nsCSSSelectorList* selectorList = nullptr;
+  bool haveCachedList = cache.GetList(aSelectorString, &selectorList);
+  if (haveCachedList) {
+    if (!selectorList) {
       // Invalid selector.
       aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR,
         NS_LITERAL_CSTRING("'") + NS_ConvertUTF16toUTF8(aSelectorString) +
         NS_LITERAL_CSTRING("' is not a valid selector")
       );
     }
-    MOZ_ASSERT(list->IsGecko(), "We haven't done anything with Servo yet");
-    return list->AsGecko();
+    return selectorList;
   }
 
   nsCSSParser parser(doc->CSSLoader());
 
-  nsCSSSelectorList* selectorList = nullptr;
   aRv = parser.ParseSelectorString(aSelectorString,
                                    doc->GetDocumentURI(),
                                    0, // XXXbz get the line number!
                                    &selectorList);
   if (aRv.Failed()) {
     // We hit this for syntax errors, which are quite common, so don't
     // use NS_ENSURE_SUCCESS.  (For example, jQuery has an extended set
     // of selectors, but it sees if we can parse them first.)
@@ -2711,17 +2709,17 @@ nsINode::ParseSelectorList(const nsAStri
                "Unexpected error, so cached version won't return it");
 
     // Change the error message to match above.
     aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR,
       NS_LITERAL_CSTRING("'") + NS_ConvertUTF16toUTF8(aSelectorString) +
       NS_LITERAL_CSTRING("' is not a valid selector")
     );
 
-    cache.CacheList(aSelectorString, UniquePtr<nsCSSSelectorList>());
+    cache.CacheList(aSelectorString, nullptr);
     return nullptr;
   }
 
   // Filter out pseudo-element selectors from selectorList
   nsCSSSelectorList** slot = &selectorList;
   do {
     nsCSSSelectorList* cur = *slot;
     if (cur->mSelectors->IsPseudoElement()) {
@@ -2731,17 +2729,17 @@ nsINode::ParseSelectorList(const nsAStri
     } else {
       slot = &cur->mNext;
     }
   } while (*slot);
 
   if (selectorList) {
     NS_ASSERTION(selectorList->mSelectors,
                  "How can we not have any selectors?");
-    cache.CacheList(aSelectorString, UniquePtr<nsCSSSelectorList>(selectorList));
+    cache.CacheList(aSelectorString, selectorList);
   } else {
     // This is the "only pseudo-element selectors" case, which is
     // not common, so just don't worry about caching it.  That way a
     // null cached value can always indicate an invalid selector.
   }
 
   return selectorList;
 }