Bug 1287951: followup: Know if a snapshot belongs to a HTML element in an HTML document at construction time. r=heycam
authorEmilio Cobos Álvarez <ecoal95@gmail.com>
Fri, 29 Jul 2016 10:50:26 -0700
changeset 347524 0e1f1a9c666d2ba8ddba5246fb4e705244edbeb4
parent 347523 77950beb90dd5636e0d3929638bdd11c899c9bd8
child 347525 a9eeb3adc7ddb5006c088e9eda61791c777cbf7c
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1287951
milestone50.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 1287951: followup: Know if a snapshot belongs to a HTML element in an HTML document at construction time. r=heycam MozReview-Commit-ID: eN0j8vnesa
layout/base/ServoRestyleManager.cpp
layout/style/ServoElementSnapshot.cpp
layout/style/ServoElementSnapshot.h
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -301,18 +301,14 @@ ServoRestyleManager::ReparentStyleContex
 {
   NS_WARNING("stylo: ServoRestyleManager::ReparentStyleContext not implemented");
   return NS_OK;
 }
 
 ServoElementSnapshot*
 ServoRestyleManager::SnapshotForElement(Element* aElement)
 {
-  ServoElementSnapshot* snapshot = mModifiedElements.LookupOrAdd(aElement);
-  if (!snapshot->HasAny(
-        ServoElementSnapshot::Flags::HTMLElementInHTMLDocument)) {
-    snapshot->SetIsHTMLElementInHTMLDocument(
-      aElement->IsHTMLElement() && aElement->OwnerDoc()->IsHTMLDocument());
-  }
-  return snapshot;
+  // NB: aElement is the argument for the construction of the snapshot in the
+  // not found case.
+  return mModifiedElements.LookupOrAdd(aElement, aElement);
 }
 
 } // namespace mozilla
--- a/layout/style/ServoElementSnapshot.cpp
+++ b/layout/style/ServoElementSnapshot.cpp
@@ -1,19 +1,30 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ServoElementSnapshot.h"
 #include "mozilla/dom/Element.h"
+#include "nsIContentInlines.h"
 
 namespace mozilla {
 
+ServoElementSnapshot::ServoElementSnapshot(Element* aElement)
+  : mContains(Flags(0))
+  , mState(0)
+  , mExplicitRestyleHint(nsRestyleHint(0))
+  , mExplicitChangeHint(nsChangeHint(0))
+{
+  mIsHTMLElementInHTMLDocument =
+    aElement->IsHTMLElement() && aElement->IsInHTMLDocument();
+}
+
 void
 ServoElementSnapshot::AddAttrs(Element* aElement)
 {
   MOZ_ASSERT(aElement);
 
   if (!HasAny(Flags::Attributes)) {
     return;
   }
--- a/layout/style/ServoElementSnapshot.h
+++ b/layout/style/ServoElementSnapshot.h
@@ -41,18 +41,17 @@ struct ServoAttrSnapshot
 /**
  * A bitflags enum class used to determine what data does a ServoElementSnapshot
  * contains.
  */
 enum class ServoElementSnapshotFlags : uint8_t
 {
   State = 1 << 0,
   Attributes = 1 << 1,
-  HTMLElementInHTMLDocument = 1 << 2,
-  All = State | Attributes | HTMLElementInHTMLDocument
+  All = State | Attributes
 };
 
 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ServoElementSnapshotFlags)
 
 /**
  * This class holds all non-tree-structural state of an element that might be
  * used for selector matching eventually.
  *
@@ -63,27 +62,17 @@ class ServoElementSnapshot
 {
   typedef dom::BorrowedAttrInfo BorrowedAttrInfo;
   typedef dom::Element Element;
   typedef EventStates::ServoType ServoStateType;
 
 public:
   typedef ServoElementSnapshotFlags Flags;
 
-  /**
-   * Empty snapshot, with no data at all.
-   */
-  ServoElementSnapshot()
-    : mContains(Flags(0))
-    , mState(0)
-    , mExplicitRestyleHint(nsRestyleHint(0))
-    , mExplicitChangeHint(nsChangeHint(0))
-    , mIsHTMLElementInHTMLDocument(false)
-  {
-  }
+  explicit ServoElementSnapshot(Element* aElement);
 
   bool HasAttrs() { return HasAny(Flags::Attributes); }
 
   bool HasState() { return HasAny(Flags::State); }
 
   /**
    * Captures the given state (if not previously captured).
    */
@@ -149,24 +138,16 @@ public:
       if (mAttrs[i].mName.Equals(aLocalName, aNamespaceID)) {
         return &mAttrs[i].mValue;
       }
     }
 
     return nullptr;
   }
 
-  void SetIsHTMLElementInHTMLDocument(bool aIs)
-  {
-    MOZ_ASSERT(!HasAny(Flags::HTMLElementInHTMLDocument),
-               "Only expected to be set once!");
-    mContains |= Flags::HTMLElementInHTMLDocument;
-    mIsHTMLElementInHTMLDocument = aIs;
-  }
-
   bool HasAny(Flags aFlags) { return bool(mContains & aFlags); }
 
 private:
   // TODO: Profile, a 1 or 2 element AutoTArray could be worth it, given we know
   // we're dealing with attribute changes when we take snapshots of attributes,
   // though it can be wasted space if we deal with a lot of state-only
   // snapshots.
   Flags mContains;