Bug 1481155 - Use more references in the snapshot code. r=xidorn

Differential Revision: https://phabricator.services.mozilla.com/D2766

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2018-08-06 23:44:56 +00:00
Родитель c0434853c1
Коммит 60a4d14017
4 изменённых файлов: 47 добавлений и 42 удалений

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

@ -496,7 +496,7 @@ RestyleManager::ContentRemoved(nsIContent* aOldChild,
* This is called from both Restyle managers.
*/
void
RestyleManager::ContentStateChangedInternal(Element* aElement,
RestyleManager::ContentStateChangedInternal(const Element& aElement,
EventStates aStateMask,
nsChangeHint* aOutChangeHint)
{
@ -510,7 +510,7 @@ RestyleManager::ContentStateChangedInternal(Element* aElement,
// based on content states, so if we already don't have a frame we don't
// need to force a reframe -- if it's needed, the HasStateDependentStyle
// call will handle things.
nsIFrame* primaryFrame = aElement->GetPrimaryFrame();
nsIFrame* primaryFrame = aElement.GetPrimaryFrame();
if (primaryFrame) {
// If it's generated content, ignore LOADING/etc state changes on it.
if (!primaryFrame->IsGeneratedContentFrame() &&
@ -2200,8 +2200,8 @@ ServoRestyleState::TableAwareParentFor(const nsIFrame* aChild)
void
RestyleManager::PostRestyleEvent(Element* aElement,
nsRestyleHint aRestyleHint,
nsChangeHint aMinChangeHint)
nsRestyleHint aRestyleHint,
nsChangeHint aMinChangeHint)
{
MOZ_ASSERT(!(aMinChangeHint & nsChangeHint_NeutralChange),
"Didn't expect explicit change hints to be neutral!");
@ -2945,7 +2945,7 @@ RestyleManager::ClearSnapshots()
}
ServoElementSnapshot&
RestyleManager::SnapshotFor(Element* aElement)
RestyleManager::SnapshotFor(Element& aElement)
{
MOZ_ASSERT(!mInStyleRefresh);
@ -2959,14 +2959,14 @@ RestyleManager::SnapshotFor(Element* aElement)
//
// Can't wait to make ProcessPendingRestyles the only entry-point for styling,
// so this becomes much easier to reason about. Today is not that day though.
MOZ_ASSERT(aElement->HasServoData());
MOZ_ASSERT(!aElement->HasFlag(ELEMENT_HANDLED_SNAPSHOT));
MOZ_ASSERT(aElement.HasServoData());
MOZ_ASSERT(!aElement.HasFlag(ELEMENT_HANDLED_SNAPSHOT));
ServoElementSnapshot* snapshot = mSnapshots.LookupOrAdd(aElement, aElement);
aElement->SetFlags(ELEMENT_HAS_SNAPSHOT);
ServoElementSnapshot* snapshot = mSnapshots.LookupOrAdd(&aElement, aElement);
aElement.SetFlags(ELEMENT_HAS_SNAPSHOT);
// Now that we have a snapshot, make sure a restyle is triggered.
aElement->NoteDirtyForServo();
aElement.NoteDirtyForServo();
return *snapshot;
}
@ -3177,30 +3177,33 @@ RestyleManager::ContentStateChanged(nsIContent* aContent,
return;
}
Element* aElement = aContent->AsElement();
if (!aElement->HasServoData()) {
Element& element = *aContent->AsElement();
if (!element.HasServoData()) {
return;
}
nsChangeHint changeHint;
ContentStateChangedInternal(aElement, aChangedBits, &changeHint);
ContentStateChangedInternal(element, aChangedBits, &changeHint);
// Don't bother taking a snapshot if no rules depend on these state bits.
//
// We always take a snapshot for the LTR/RTL event states, since Servo doesn't
// track those bits in the same way, and we know that :dir() rules are always
// present in UA style sheets.
//
// FIXME(emilio): Doesn't this early-return drop the change hint on the floor?
// Should it?
if (!aChangedBits.HasAtLeastOneOfStates(DIRECTION_STATES) &&
!StyleSet()->HasStateDependency(*aElement, aChangedBits)) {
!StyleSet()->HasStateDependency(element, aChangedBits)) {
return;
}
ServoElementSnapshot& snapshot = SnapshotFor(aElement);
EventStates previousState = aElement->StyleState() ^ aChangedBits;
ServoElementSnapshot& snapshot = SnapshotFor(element);
EventStates previousState = element.StyleState() ^ aChangedBits;
snapshot.AddState(previousState);
if (changeHint) {
Servo_NoteExplicitHints(aElement, nsRestyleHint(0), changeHint);
Servo_NoteExplicitHints(&element, nsRestyleHint(0), changeHint);
}
// Assuming we need to invalidate cached style in getComputedStyle for
@ -3271,30 +3274,30 @@ RestyleManager::AttributeWillChange(Element* aElement,
int32_t aModType,
const nsAttrValue* aNewValue)
{
TakeSnapshotForAttributeChange(aElement, aNameSpaceID, aAttribute);
TakeSnapshotForAttributeChange(*aElement, aNameSpaceID, aAttribute);
}
void
RestyleManager::ClassAttributeWillBeChangedBySMIL(Element* aElement)
{
TakeSnapshotForAttributeChange(aElement, kNameSpaceID_None,
TakeSnapshotForAttributeChange(*aElement, kNameSpaceID_None,
nsGkAtoms::_class);
}
void
RestyleManager::TakeSnapshotForAttributeChange(Element* aElement,
RestyleManager::TakeSnapshotForAttributeChange(Element& aElement,
int32_t aNameSpaceID,
nsAtom* aAttribute)
{
MOZ_ASSERT(!mInStyleRefresh);
if (!aElement->HasServoData()) {
if (!aElement.HasServoData()) {
return;
}
bool influencesOtherPseudoClassState;
if (!NeedToRecordAttrChange(*StyleSet(),
*aElement,
aElement,
aNameSpaceID,
aAttribute,
&influencesOtherPseudoClassState)) {

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

@ -472,7 +472,9 @@ protected:
void RestyleForEmptyChange(Element* aContainer);
void MaybeRestyleForEdgeChildChange(Element* aContainer, nsIContent* aChangedChild);
void ContentStateChangedInternal(Element* aElement,
// TODO(emilio): there's no good reason this isn't part of ContentStateChanged
// now, or the change hint isn't returned instead of via an out-param, really.
void ContentStateChangedInternal(const Element&,
EventStates aStateMask,
nsChangeHint* aOutChangeHint);
@ -529,8 +531,8 @@ protected:
const SnapshotTable& Snapshots() const { return mSnapshots; }
void ClearSnapshots();
ServoElementSnapshot& SnapshotFor(mozilla::dom::Element* aElement);
void TakeSnapshotForAttributeChange(mozilla::dom::Element* aElement,
ServoElementSnapshot& SnapshotFor(Element&);
void TakeSnapshotForAttributeChange(Element&,
int32_t aNameSpaceID,
nsAtom* aAttribute);

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

@ -12,7 +12,7 @@
namespace mozilla {
ServoElementSnapshot::ServoElementSnapshot(const Element* aElement)
ServoElementSnapshot::ServoElementSnapshot(const Element& aElement)
: mState(0)
, mContains(Flags(0))
, mIsTableBorderNonzero(false)
@ -22,23 +22,22 @@ ServoElementSnapshot::ServoElementSnapshot(const Element* aElement)
, mOtherAttributeChanged(false)
{
MOZ_COUNT_CTOR(ServoElementSnapshot);
MOZ_ASSERT(NS_IsMainThread());
mIsHTMLElementInHTMLDocument =
aElement->IsHTMLElement() && aElement->IsInHTMLDocument();
mIsInChromeDocument = nsContentUtils::IsChromeDoc(aElement->OwnerDoc());
mSupportsLangAttr = aElement->SupportsLangAttr();
aElement.IsHTMLElement() && aElement.IsInHTMLDocument();
mIsInChromeDocument = nsContentUtils::IsChromeDoc(aElement.OwnerDoc());
mSupportsLangAttr = aElement.SupportsLangAttr();
}
void
ServoElementSnapshot::AddOtherPseudoClassState(Element* aElement)
ServoElementSnapshot::AddOtherPseudoClassState(const Element& aElement)
{
MOZ_ASSERT(aElement);
if (HasOtherPseudoClassState()) {
return;
}
mIsTableBorderNonzero = Gecko_IsTableBorderNonzero(aElement);
mIsMozBrowserFrame = Gecko_IsBrowserFrame(aElement);
mIsTableBorderNonzero = Gecko_IsTableBorderNonzero(&aElement);
mIsMozBrowserFrame = Gecko_IsBrowserFrame(&aElement);
mContains |= Flags::OtherPseudoClassState;
}

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

@ -67,10 +67,11 @@ class ServoElementSnapshot
public:
typedef ServoElementSnapshotFlags Flags;
explicit ServoElementSnapshot(const Element* aElement);
explicit ServoElementSnapshot(const Element&);
~ServoElementSnapshot()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_DTOR(ServoElementSnapshot);
}
@ -100,13 +101,13 @@ public:
* The attribute name and namespace are used to note which kind of attribute
* has changed.
*/
inline void AddAttrs(Element*, int32_t aNameSpaceID, nsAtom* aAttribute);
inline void AddAttrs(const Element&, int32_t aNameSpaceID, nsAtom* aAttribute);
/**
* Captures some other pseudo-class matching state not included in
* EventStates.
*/
void AddOtherPseudoClassState(Element* aElement);
void AddOtherPseudoClassState(const Element&);
/**
* Needed methods for attribute matching.
@ -194,7 +195,7 @@ private:
inline void
ServoElementSnapshot::AddAttrs(mozilla::dom::Element* aElement,
ServoElementSnapshot::AddAttrs(const Element& aElement,
int32_t aNameSpaceID,
nsAtom* aAttribute)
{
@ -214,20 +215,20 @@ ServoElementSnapshot::AddAttrs(mozilla::dom::Element* aElement,
return;
}
uint32_t attrCount = aElement->GetAttrCount();
uint32_t attrCount = aElement.GetAttrCount();
mAttrs.SetCapacity(attrCount);
for (uint32_t i = 0; i < attrCount; ++i) {
const BorrowedAttrInfo info = aElement->GetAttrInfoAt(i);
const BorrowedAttrInfo info = aElement.GetAttrInfoAt(i);
MOZ_ASSERT(info);
mAttrs.AppendElement(ServoAttrSnapshot { *info.mName, *info.mValue });
}
mContains |= Flags::Attributes;
if (aElement->HasID()) {
if (aElement.HasID()) {
mContains |= Flags::Id;
}
if (const nsAttrValue* classValue = aElement->GetClasses()) {
if (const nsAttrValue* classValue = aElement.GetClasses()) {
// FIXME(emilio): It's pretty unfortunate that this is only relevant for
// SVG, yet it's a somewhat expensive copy. We should be able to do
// better!