Bug 1438688, part 2b - Eliminate XPTHeader data structure. r=njn
authorAndrew McCreight <continuation@gmail.com>
Tue, 27 Mar 2018 14:04:01 -0700
changeset 776568 1f3b60346b7750df21c3a93a2eef0d801d77e421
parent 776567 e3b0f068f61e4b352072c1246609ad5c50930587
child 776569 af6c0673ec6ffc38d30d95ea42caa7001cd19ef4
push id104907
push userbmo:ato@sny.no
push dateTue, 03 Apr 2018 10:28:20 +0000
reviewersnjn
bugs1438688
milestone61.0a1
Bug 1438688, part 2b - Eliminate XPTHeader data structure. r=njn Now that there is only one XPTHeader, we can devolve the fields in it to avoid some indirection. The biggest part here is getting rid of the mHeader field on xptiTypelibGuts. The array is [] instead of * to avoid a relocation, by ensuring that XPTHeader::kInterfaceDirectory as well as the data it points to cannot be changed. MozReview-Commit-ID: AzvNTNZKkfi
xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
xpcom/reflect/xptinfo/xptiprivate.h
xpcom/typelib/xpt/xpt_struct.h
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
@@ -76,21 +76,21 @@ XPTInterfaceInfoManager::FreeInterfaceIn
 {
     gInterfaceInfoManager = nullptr;
 }
 
 XPTInterfaceInfoManager::XPTInterfaceInfoManager()
     :   mWorkingSet(),
         mResolveLock("XPTInterfaceInfoManager.mResolveLock")
 {
-    xptiTypelibGuts* typelib = xptiTypelibGuts::Create(&XPTHeader::kHeader);
+    xptiTypelibGuts* typelib = xptiTypelibGuts::Create();
 
     ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
-    for (uint16_t k = 0; k < XPTHeader::kHeader.mNumInterfaces; k++) {
-        VerifyAndAddEntryIfNew(XPTHeader::kHeader.mInterfaceDirectory + k, k, typelib);
+    for (uint16_t k = 0; k < XPTHeader::kNumInterfaces; k++) {
+        VerifyAndAddEntryIfNew(XPTHeader::kInterfaceDirectory + k, k, typelib);
     }
 }
 
 XPTInterfaceInfoManager::~XPTInterfaceInfoManager()
 {
     // We only do this on shutdown of the service.
     mWorkingSet.InvalidateInterfaceInfos();
 
--- a/xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
+++ b/xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
@@ -15,41 +15,39 @@ using namespace mozilla;
 template <class T>
 class MOZ_NEEDS_NO_VTABLE_TYPE CheckNoVTable
 {
 };
 CheckNoVTable<xptiTypelibGuts> gChecker;
 
 // static
 xptiTypelibGuts*
-xptiTypelibGuts::Create(const XPTHeader* aHeader)
+xptiTypelibGuts::Create()
 {
-    NS_ASSERTION(aHeader, "bad param");
     size_t n = sizeof(xptiTypelibGuts) +
-               sizeof(xptiInterfaceEntry*) * (aHeader->mNumInterfaces - 1);
+               sizeof(xptiInterfaceEntry*) * (XPTHeader::kNumInterfaces - 1);
     void* place = XPT_CALLOC8(gXPTIStructArena, n);
     if (!place)
         return nullptr;
-    return new(place) xptiTypelibGuts(aHeader);
+    return new(place) xptiTypelibGuts();
 }
 
 xptiInterfaceEntry*
 xptiTypelibGuts::GetEntryAt(uint16_t i)
 {
     static const nsID zeroIID =
         { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
 
-    NS_ASSERTION(mHeader, "bad state");
     NS_ASSERTION(i < GetEntryCount(), "bad index");
 
     xptiInterfaceEntry* r = mEntryArray[i];
     if (r)
         return r;
 
-    const XPTInterfaceDirectoryEntry* iface = mHeader->mInterfaceDirectory + i;
+    const XPTInterfaceDirectoryEntry* iface = XPTHeader::kInterfaceDirectory + i;
 
     XPTInterfaceInfoManager::xptiWorkingSet& set =
         XPTInterfaceInfoManager::GetSingleton()->mWorkingSet;
 
     {
         ReentrantMonitorAutoEnter monitor(set.mTableReentrantMonitor);
         if (iface->mIID.Equals(zeroIID))
             r = set.mNameTable.Get(iface->Name());
@@ -61,15 +59,14 @@ xptiTypelibGuts::GetEntryAt(uint16_t i)
         SetEntryAt(i, r);
 
     return r;
 }
 
 const char*
 xptiTypelibGuts::GetEntryNameAt(uint16_t i)
 {
-    NS_ASSERTION(mHeader, "bad state");
     NS_ASSERTION(i < GetEntryCount(), "bad index");
 
-    const XPTInterfaceDirectoryEntry* iface = mHeader->mInterfaceDirectory + i;
+    const XPTInterfaceDirectoryEntry* iface = XPTHeader::kInterfaceDirectory + i;
 
     return iface->Name();
 }
--- a/xpcom/reflect/xptinfo/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/xptiprivate.h
@@ -70,38 +70,34 @@ extern XPTArena* gXPTIStructArena;
 
 // No virtuals.
 // These are always constructed in the struct arena using placement new.
 // dtor need not be called.
 
 class xptiTypelibGuts
 {
 public:
-    static xptiTypelibGuts* Create(const XPTHeader* aHeader);
+    static xptiTypelibGuts* Create();
 
-    uint16_t GetEntryCount() const {return mHeader->mNumInterfaces;}
+    uint16_t GetEntryCount() const { return XPTHeader::kNumInterfaces; }
 
     void                SetEntryAt(uint16_t i, xptiInterfaceEntry* ptr)
     {
-        NS_ASSERTION(mHeader,"bad state!");
         NS_ASSERTION(i < GetEntryCount(),"bad param!");
         mEntryArray[i] = ptr;
     }
 
     xptiInterfaceEntry* GetEntryAt(uint16_t i);
     const char* GetEntryNameAt(uint16_t i);
 
 private:
-    explicit xptiTypelibGuts(const XPTHeader* aHeader)
-        : mHeader(aHeader)
-    { }
+    xptiTypelibGuts() = default;
     ~xptiTypelibGuts();
 
 private:
-    const XPTHeader*     mHeader;        // hold pointer into arena
     xptiInterfaceEntry*  mEntryArray[1]; // Always last. Sized to fit.
 };
 
 /***************************************************************************/
 
 /***************************************************************************/
 
 // This class exists to help xptiInterfaceInfo store a 4-state (2 bit) value
--- a/xpcom/typelib/xpt/xpt_struct.h
+++ b/xpcom/typelib/xpt/xpt_struct.h
@@ -20,20 +20,18 @@ struct XPTInterfaceDirectoryEntry;
 struct XPTInterfaceDescriptor;
 struct XPTConstDescriptor;
 struct XPTMethodDescriptor;
 struct XPTParamDescriptor;
 struct XPTTypeDescriptor;
 struct XPTTypeDescriptorPrefix;
 
 struct XPTHeader {
-  uint16_t mNumInterfaces;
-  const XPTInterfaceDirectoryEntry* mInterfaceDirectory;
-
-  static const XPTHeader kHeader;
+  static const uint16_t kNumInterfaces;
+  static const XPTInterfaceDirectoryEntry kInterfaceDirectory[];
 };
 
 /*
  * An array of directory entries is used to quickly locate an interface
  * description using its IID. No interface should appear more than once in the
  * array.
  */
 struct XPTInterfaceDirectoryEntry {