Backed out changeset 9a8f77f3dfe7 (bug 1404897)

This commit is contained in:
Sebastian Hengst 2017-10-04 12:55:16 +02:00
Родитель d90f0a5f6d
Коммит 635c45113c
3 изменённых файлов: 14 добавлений и 122 удалений

Просмотреть файл

@ -1406,39 +1406,13 @@ nsIDocument::SelectorCache::~SelectorCache()
AgeAllGenerations(); 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. // CacheList takes ownership of aSelectorList.
void nsIDocument::SelectorCache::CacheList(const nsAString& aSelector, void nsIDocument::SelectorCache::CacheList(const nsAString& aSelector,
mozilla::UniquePtr<nsCSSSelectorList>&& aSelectorList) nsCSSSelectorList* aSelectorList)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
SelectorCacheKey* key = new SelectorCacheKey(aSelector); SelectorCacheKey* key = new SelectorCacheKey(aSelector);
mTable.Put(key->mKey, SelectorList(Move(aSelectorList))); mTable.Put(key->mKey, 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)));
AddObject(key); AddObject(key);
} }

Просмотреть файл

@ -37,7 +37,6 @@
#include "mozilla/LinkedList.h" #include "mozilla/LinkedList.h"
#include "mozilla/NotNull.h" #include "mozilla/NotNull.h"
#include "mozilla/SegmentedVector.h" #include "mozilla/SegmentedVector.h"
#include "mozilla/ServoBindingTypes.h"
#include "mozilla/StyleBackendType.h" #include "mozilla/StyleBackendType.h"
#include "mozilla/StyleSheet.h" #include "mozilla/StyleSheet.h"
#include "mozilla/TimeStamp.h" #include "mozilla/TimeStamp.h"
@ -1149,106 +1148,27 @@ public:
: public nsExpirationTracker<SelectorCacheKey, 4> : public nsExpirationTracker<SelectorCacheKey, 4>
{ {
public: 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;
explicit SelectorList(mozilla::UniquePtr<RawServoSelectorList>&& aList)
: mIsServo(true)
, mServo(aList.release())
{}
explicit 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); explicit SelectorCache(nsIEventTarget* aEventTarget);
// CacheList takes ownership of aSelectorList. // CacheList takes ownership of aSelectorList.
void CacheList(const nsAString& aSelector, void CacheList(const nsAString& aSelector, nsCSSSelectorList* aSelectorList);
mozilla::UniquePtr<nsCSSSelectorList>&& aSelectorList);
void CacheList(const nsAString& aSelector,
mozilla::UniquePtr<RawServoSelectorList>&& aSelectorList);
virtual void NotifyExpired(SelectorCacheKey* aSelector) override; virtual void NotifyExpired(SelectorCacheKey* aSelector) override;
// We do not call MarkUsed because it would just slow down lookups and // 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 // 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. // being used. Returns whether we actually had an entry for aSelector.
// // If we have an entry and *aList is null, that indicates that aSelector
// If we have an entry and the selector list returned has a null
// nsCSSSelectorList*/RawServoSelectorList*, that indicates that aSelector
// has already been parsed and is not a syntactically valid selector. // 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(); ~SelectorCache();
private: private:
nsDataHashtable<nsStringHashKey, SelectorList> mTable; nsClassHashtable<nsStringHashKey, nsCSSSelectorList> mTable;
}; };
SelectorCache& GetSelectorCache() { SelectorCache& GetSelectorCache() {

Просмотреть файл

@ -2682,23 +2682,21 @@ nsINode::ParseSelectorList(const nsAString& aSelectorString,
{ {
nsIDocument* doc = OwnerDoc(); nsIDocument* doc = OwnerDoc();
nsIDocument::SelectorCache& cache = doc->GetSelectorCache(); nsIDocument::SelectorCache& cache = doc->GetSelectorCache();
nsIDocument::SelectorCache::SelectorList* list = nsCSSSelectorList* selectorList = nullptr;
cache.GetList(aSelectorString); bool haveCachedList = cache.GetList(aSelectorString, &selectorList);
if (list) { if (haveCachedList) {
if (!*list) { if (!selectorList) {
// Invalid selector. // Invalid selector.
aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR, aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR,
NS_LITERAL_CSTRING("'") + NS_ConvertUTF16toUTF8(aSelectorString) + NS_LITERAL_CSTRING("'") + NS_ConvertUTF16toUTF8(aSelectorString) +
NS_LITERAL_CSTRING("' is not a valid selector") NS_LITERAL_CSTRING("' is not a valid selector")
); );
} }
MOZ_ASSERT(list->IsGecko(), "We haven't done anything with Servo yet"); return selectorList;
return list->AsGecko();
} }
nsCSSParser parser(doc->CSSLoader()); nsCSSParser parser(doc->CSSLoader());
nsCSSSelectorList* selectorList = nullptr;
aRv = parser.ParseSelectorString(aSelectorString, aRv = parser.ParseSelectorString(aSelectorString,
doc->GetDocumentURI(), doc->GetDocumentURI(),
0, // XXXbz get the line number! 0, // XXXbz get the line number!
@ -2716,7 +2714,7 @@ nsINode::ParseSelectorList(const nsAString& aSelectorString,
NS_LITERAL_CSTRING("' is not a valid selector") NS_LITERAL_CSTRING("' is not a valid selector")
); );
cache.CacheList(aSelectorString, UniquePtr<nsCSSSelectorList>()); cache.CacheList(aSelectorString, nullptr);
return nullptr; return nullptr;
} }
@ -2736,7 +2734,7 @@ nsINode::ParseSelectorList(const nsAString& aSelectorString,
if (selectorList) { if (selectorList) {
NS_ASSERTION(selectorList->mSelectors, NS_ASSERTION(selectorList->mSelectors,
"How can we not have any selectors?"); "How can we not have any selectors?");
cache.CacheList(aSelectorString, UniquePtr<nsCSSSelectorList>(selectorList)); cache.CacheList(aSelectorString, selectorList);
} else { } else {
// This is the "only pseudo-element selectors" case, which is // This is the "only pseudo-element selectors" case, which is
// not common, so just don't worry about caching it. That way a // not common, so just don't worry about caching it. That way a