try: -b do -p all -u all -t none
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 07 Aug 2018 18:35:05 +0300
changeset 1660247 739c792f41fa28fdbc237b845eb4163a3852bf61
parent 1660246 ed961def65099d39a30ef6e8c1476ad3033c1361
child 2270591 0a31466310e3370a7657161847228f860d5c5ac8
push id289697
push useropettay@mozilla.com
push dateTue, 07 Aug 2018 15:35:35 +0000
treeherdertry@739c792f41fa [default view] [failures only]
milestone63.0a1
try: -b do -p all -u all -t none
dom/base/AttrArray.cpp
dom/base/AttrArray.h
dom/base/Element.cpp
--- a/dom/base/AttrArray.cpp
+++ b/dom/base/AttrArray.cpp
@@ -19,69 +19,16 @@
 #include "nsString.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsMappedAttributes.h"
 #include "nsUnicharUtils.h"
 #include "nsContentUtils.h" // nsAutoScriptBlocker
 
 using mozilla::CheckedUint32;
 
-/*
-CACHE_POINTER_SHIFT indicates how many steps to downshift the |this| pointer.
-It should be small enough to not cause collisions between adjecent arrays, and
-large enough to make sure that all indexes are used. The size below is based
-on the size of the smallest possible element (currently 20[*] bytes) which is
-the smallest distance between two AttrArray. 20/(2^_5_) is 0.625.
-This means that two adjacent AttrArrays will overlap one in 2.7 times.
-However not all elements will have enough children to get cached. And any
-allocator that doesn't return addresses aligned to 64 bytes will ensure that
-any index will get used.
-
-[*] sizeof(Element).  Except is that really 20 bytes?  Seems dubious!
-*/
-
-#define CACHE_POINTER_SHIFT 5
-#define CACHE_NUM_SLOTS 128
-#define CACHE_CHILD_LIMIT 10
-
-#define CACHE_GET_INDEX(_array) \
-  ((NS_PTR_TO_INT32(_array) >> CACHE_POINTER_SHIFT) & \
-   (CACHE_NUM_SLOTS - 1))
-
-struct IndexCacheSlot
-{
-  const AttrArray* array;
-  int32_t index;
-};
-
-// This is inited to all zeroes since it's static. Though even if it wasn't
-// the worst thing that'd happen is a small inefficency if you'd get a false
-// positive cachehit.
-static IndexCacheSlot indexCache[CACHE_NUM_SLOTS];
-
-static
-inline
-void
-AddIndexToCache(const AttrArray* aArray, int32_t aIndex)
-{
-  uint32_t ix = CACHE_GET_INDEX(aArray);
-  indexCache[ix].array = aArray;
-  indexCache[ix].index = aIndex;
-}
-
-static
-inline
-int32_t
-GetIndexFromCache(const AttrArray* aArray)
-{
-  uint32_t ix = CACHE_GET_INDEX(aArray);
-  return indexCache[ix].array == aArray ? indexCache[ix].index : -1;
-}
-
-
 /**
  * Due to a compiler bug in VisualAge C++ for AIX, we need to return the
  * address of the first index into mBuffer here, instead of simply returning
  * mBuffer itself.
  *
  * See Bug 231104 for more information.
  */
 #define ATTRS(_impl) \
@@ -213,19 +160,16 @@ AttrArray::SetAndSwapAttr(nsAtom* aLocal
   for (i = 0; i < slotCount && AttrSlotIsTaken(i); ++i) {
     if (ATTRS(mImpl)[i].mName.Equals(aLocalName)) {
       ATTRS(mImpl)[i].mValue.SwapValueWith(aValue);
       *aHadValue = true;
       return NS_OK;
     }
   }
 
-  NS_ENSURE_TRUE(i < ATTRCHILD_ARRAY_MAX_ATTR_COUNT,
-                 NS_ERROR_FAILURE);
-
   if (i == slotCount && !AddAttrSlot()) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   new (&ATTRS(mImpl)[i].mName) nsAttrName(aLocalName);
   new (&ATTRS(mImpl)[i].mValue) nsAttrValue();
   ATTRS(mImpl)[i].mValue.SwapValueWith(aValue);
 
@@ -248,19 +192,16 @@ AttrArray::SetAndSwapAttr(mozilla::dom::
     if (ATTRS(mImpl)[i].mName.Equals(localName, namespaceID)) {
       ATTRS(mImpl)[i].mName.SetTo(aName);
       ATTRS(mImpl)[i].mValue.SwapValueWith(aValue);
       *aHadValue = true;
       return NS_OK;
     }
   }
 
-  NS_ENSURE_TRUE(i < ATTRCHILD_ARRAY_MAX_ATTR_COUNT,
-                 NS_ERROR_FAILURE);
-
   if (i == slotCount && !AddAttrSlot()) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   new (&ATTRS(mImpl)[i].mName) nsAttrName(aName);
   new (&ATTRS(mImpl)[i].mValue) nsAttrValue();
   ATTRS(mImpl)[i].mValue.SwapValueWith(aValue);
 
@@ -498,17 +439,17 @@ AttrArray::Clear()
     NS_RELEASE(mImpl->mMappedAttrs);
   }
 
   uint32_t i, slotCount = AttrSlotCount();
   for (i = 0; i < slotCount && AttrSlotIsTaken(i); ++i) {
     ATTRS(mImpl)[i].~InternalAttr();
   }
 
-  SetAttrSlotAndChildCount(0, 0);
+  SetAttrSlotCount(0);
 }
 
 uint32_t
 AttrArray::NonMappedAttrCount() const
 {
   if (!mImpl) {
     return 0;
   }
@@ -625,17 +566,17 @@ AttrArray::EnsureCapacityToClone(const A
 
   mImpl->mMappedAttrs = nullptr;
   mImpl->mBufferSize = size;
 
   // The array is now the right size, but we should reserve the correct
   // number of slots for attributes so that children don't get written into
   // that part of the array (which will then need to be moved later).
   memset(static_cast<void*>(mImpl->mBuffer), 0, sizeof(InternalAttr) * attrCount);
-  SetAttrSlotAndChildCount(attrCount, 0);
+  SetAttrSlotCount(attrCount);
 
   return NS_OK;
 }
 
 bool
 AttrArray::GrowBy(uint32_t aGrowSize)
 {
   CheckedUint32 size = 0;
@@ -680,17 +621,17 @@ AttrArray::GrowBy(uint32_t aGrowSize)
   Impl* newImpl = static_cast<Impl*>(realloc(mImpl, neededSize.value()));
   NS_ENSURE_TRUE(newImpl, false);
 
   mImpl = newImpl;
 
   // Set initial counts if we didn't have a buffer before
   if (needToInitialize) {
     mImpl->mMappedAttrs = nullptr;
-    SetAttrSlotAndChildCount(0, 0);
+    SetAttrSlotCount(0);
   }
 
   mImpl->mBufferSize = size.value() - NS_IMPL_EXTRA_SIZE;
 
   return true;
 }
 
 bool
--- a/dom/base/AttrArray.h
+++ b/dom/base/AttrArray.h
@@ -25,28 +25,16 @@ class nsIContent;
 class nsMappedAttributes;
 class nsHTMLStyleSheet;
 class nsRuleWalker;
 class nsMappedAttributeElement;
 
 #define ATTRCHILD_ARRAY_GROWSIZE 8
 #define ATTRCHILD_ARRAY_LINEAR_THRESHOLD 32
 
-#define ATTRCHILD_ARRAY_ATTR_SLOTS_BITS 10
-
-#define ATTRCHILD_ARRAY_MAX_ATTR_COUNT \
-    ((1 << ATTRCHILD_ARRAY_ATTR_SLOTS_BITS) - 1)
-
-#define ATTRCHILD_ARRAY_MAX_CHILD_COUNT \
-    (~uint32_t(0) >> ATTRCHILD_ARRAY_ATTR_SLOTS_BITS)
-
-#define ATTRCHILD_ARRAY_ATTR_SLOTS_COUNT_MASK \
-    ((1 << ATTRCHILD_ARRAY_ATTR_SLOTS_BITS) - 1)
-
-
 #define ATTRSIZE (sizeof(InternalAttr) / sizeof(void*))
 
 class AttrArray
 {
   typedef mozilla::dom::BorrowedAttrInfo BorrowedAttrInfo;
 public:
   AttrArray();
   ~AttrArray();
@@ -115,22 +103,16 @@ public:
     if (!mImpl || !mImpl->mMappedAttrs) {
       return NS_OK;
     }
     return DoUpdateMappedAttrRuleMapper(aElement);
   }
 
   void Compact();
 
-  bool CanFitMoreAttrs() const
-  {
-    return AttrSlotCount() < ATTRCHILD_ARRAY_MAX_ATTR_COUNT ||
-           !AttrSlotIsTaken(ATTRCHILD_ARRAY_MAX_ATTR_COUNT - 1);
-  }
-
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
   bool HasMappedAttrs() const
   {
     return MappedAttrCount();
   }
   const nsMappedAttributes* GetMapped() const;
 
   // Force this to have mapped attributes, even if those attributes are empty.
@@ -166,43 +148,28 @@ private:
 
   uint32_t AttrSlotsSize() const
   {
     return AttrSlotCount() * ATTRSIZE;
   }
 
   uint32_t AttrSlotCount() const
   {
-    return mImpl ? mImpl->mAttrAndChildCount & ATTRCHILD_ARRAY_ATTR_SLOTS_COUNT_MASK : 0;
+    return mImpl ? mImpl->mAttrCount : 0;
   }
 
   bool AttrSlotIsTaken(uint32_t aSlot) const
   {
     MOZ_ASSERT(aSlot < AttrSlotCount(), "out-of-bounds");
     return mImpl->mBuffer[aSlot * ATTRSIZE];
   }
 
-  void SetChildCount(uint32_t aCount)
-  {
-    mImpl->mAttrAndChildCount =
-        (mImpl->mAttrAndChildCount & ATTRCHILD_ARRAY_ATTR_SLOTS_COUNT_MASK) |
-        (aCount << ATTRCHILD_ARRAY_ATTR_SLOTS_BITS);
-  }
-
   void SetAttrSlotCount(uint32_t aCount)
   {
-    mImpl->mAttrAndChildCount =
-        (mImpl->mAttrAndChildCount & ~ATTRCHILD_ARRAY_ATTR_SLOTS_COUNT_MASK) |
-        aCount;
-  }
-
-  void SetAttrSlotAndChildCount(uint32_t aSlotCount, uint32_t aChildCount)
-  {
-    mImpl->mAttrAndChildCount = aSlotCount |
-      (aChildCount << ATTRCHILD_ARRAY_ATTR_SLOTS_BITS);
+    mImpl->mAttrCount = aCount;
   }
 
   bool GrowBy(uint32_t aGrowSize);
   bool AddAttrSlot();
 
   /**
    * Guts of SetMappedAttrStyleSheet for the rare case when we have mapped attrs
    */
@@ -215,17 +182,17 @@ private:
 
   struct InternalAttr
   {
     nsAttrName mName;
     nsAttrValue mValue;
   };
 
   struct Impl {
-    uint32_t mAttrAndChildCount;
+    uint32_t mAttrCount;
     uint32_t mBufferSize;
     nsMappedAttributes* mMappedAttrs;
     void* mBuffer[1];
   };
 
   Impl* mImpl;
 };
 
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -2502,20 +2502,16 @@ Element::OnlyNotifySameValueSet(int32_t 
   return true;
 }
 
 nsresult
 Element::SetSingleClassFromParser(nsAtom* aSingleClassName)
 {
   // Keep this in sync with SetAttr and SetParsedAttr below.
 
-  if (!mAttrs.CanFitMoreAttrs()) {
-    return NS_ERROR_FAILURE;
-  }
-
   nsAttrValue value(aSingleClassName);
 
   nsIDocument* document = GetComposedDoc();
   mozAutoDocUpdate updateBatch(document, false);
 
   // In principle, BeforeSetAttr should be called here if a node type
   // existed that wanted to do something special for class, but there
   // is no such node type, so calling SetMayHaveClass() directly.
@@ -2543,20 +2539,16 @@ Element::SetAttr(int32_t aNamespaceID, n
 {
   // Keep this in sync with SetParsedAttr below and SetSingleClassFromParser
   // above.
 
   NS_ENSURE_ARG_POINTER(aName);
   NS_ASSERTION(aNamespaceID != kNameSpaceID_Unknown,
                "Don't call SetAttr with unknown namespace");
 
-  if (!mAttrs.CanFitMoreAttrs()) {
-    return NS_ERROR_FAILURE;
-  }
-
   uint8_t modType;
   bool hasListeners;
   // We don't want to spend time preparsing class attributes if the value is not
   // changing, so just init our nsAttrValueOrString with aValue for the
   // OnlyNotifySameValueSet call.
   nsAttrValueOrString value(aValue);
   nsAttrValue oldValue;
   bool oldValueSet;
@@ -2610,21 +2602,16 @@ Element::SetParsedAttr(int32_t aNamespac
                        bool aNotify)
 {
   // Keep this in sync with SetAttr and SetSingleClassFromParser above
 
   NS_ENSURE_ARG_POINTER(aName);
   NS_ASSERTION(aNamespaceID != kNameSpaceID_Unknown,
                "Don't call SetAttr with unknown namespace");
 
-  if (!mAttrs.CanFitMoreAttrs()) {
-    return NS_ERROR_FAILURE;
-  }
-
-
   uint8_t modType;
   bool hasListeners;
   nsAttrValueOrString value(aParsedValue);
   nsAttrValue oldValue;
   bool oldValueSet;
 
   if (OnlyNotifySameValueSet(aNamespaceID, aName, aPrefix, value, aNotify,
                              oldValue, &modType, &hasListeners, &oldValueSet)) {