Bug 1441255, part 2 - Don't make an extra copy of the name string in xptiInterfaceEntry. r=njn draft
authorAndrew McCreight <continuation@gmail.com>
Mon, 26 Feb 2018 11:10:16 -0800
changeset 759902 e3fec3866a660892d17abe81c35e117d1aec3f23
parent 759901 7be4e22947beb2f78293687ebfe33d0c0d779c9c
push id100506
push userbmo:continuation@gmail.com
push dateMon, 26 Feb 2018 19:46:01 +0000
reviewersnjn
bugs1441255
milestone60.0a1
Bug 1441255, part 2 - Don't make an extra copy of the name string in xptiInterfaceEntry. r=njn MozReview-Commit-ID: DBOcq2ZNqKu
xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
xpcom/reflect/xptinfo/xptiprivate.h
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
@@ -15,41 +15,37 @@
 using namespace mozilla;
 
 /* static */ xptiInterfaceEntry*
 xptiInterfaceEntry::Create(const char* aName,
                            const nsID& aIID,
                            XPTInterfaceDescriptor* aDescriptor,
                            xptiTypelibGuts* aTypelib)
 {
-    int namelen = strlen(aName);
-    void* place =
-        XPT_CALLOC8(gXPTIStructArena, sizeof(xptiInterfaceEntry) + namelen);
+    void* place = XPT_CALLOC8(gXPTIStructArena, sizeof(xptiInterfaceEntry));
     if (!place) {
         return nullptr;
     }
-    return new (place) xptiInterfaceEntry(aName, namelen, aIID, aDescriptor,
-                                          aTypelib);
+    return new (place) xptiInterfaceEntry(aName, aIID, aDescriptor, aTypelib);
 }
 
 xptiInterfaceEntry::xptiInterfaceEntry(const char* aName,
-                                       size_t aNameLength,
                                        const nsID& aIID,
                                        XPTInterfaceDescriptor* aDescriptor,
                                        xptiTypelibGuts* aTypelib)
     : mIID(aIID)
     , mDescriptor(aDescriptor)
     , mTypelib(aTypelib)
     , mParent(nullptr)
     , mInfo(nullptr)
     , mMethodBaseIndex(0)
     , mConstantBaseIndex(0)
     , mFlags(0)
+    , mName(aName)
 {
-    memcpy(mName, aName, aNameLength);
     SetResolvedState(PARTIALLY_RESOLVED);
 }
 
 bool
 xptiInterfaceEntry::Resolve()
 {
     MutexAutoLock lock(XPTInterfaceInfoManager::GetResolveLock());
     return ResolveLocked();
--- a/xpcom/reflect/xptinfo/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/xptiprivate.h
@@ -262,17 +262,16 @@ public:
     nsresult GetNameShared(const char **name);
     nsresult GetIIDShared(const nsIID * *iid);
     nsresult IsFunction(bool *_retval);
     nsresult HasAncestor(const nsIID * iid, bool *_retval);
     nsresult GetIIDForParamNoAlloc(uint16_t methodIndex, const nsXPTParamInfo * param, nsIID *iid);
 
 private:
     xptiInterfaceEntry(const char* aName,
-                       size_t aNameLength,
                        const nsID& aIID,
                        XPTInterfaceDescriptor* aDescriptor,
                        xptiTypelibGuts* aTypelib);
     ~xptiInterfaceEntry();
 
     void SetResolvedState(int state)
         {mFlags.SetState(uint8_t(state));}
 
@@ -315,17 +314,17 @@ private:
                                       "by the semantics of xptiWorkingSet.")
                             mInfo;        // May come and go.
 
     uint16_t mMethodBaseIndex;
     uint16_t mConstantBaseIndex;
 
     xptiInfoFlags           mFlags;
 
-    char                    mName[1];     // Always last. Sized to fit.
+    const char*             mName;
 };
 
 class xptiInterfaceInfo final : public nsIInterfaceInfo
 {
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
 
     // Use delegation to implement (most!) of nsIInterfaceInfo.