Bug 1442363, part 5 - Constify XPTInterfaceDescriptor::method_descriptors. r=njn
authorAndrew McCreight <continuation@gmail.com>
Tue, 27 Feb 2018 15:28:16 -0800
changeset 462076 05a7101669f8e2af7f35591548c28a158e2d08af
parent 462075 4a4ea07f646712675cc96ce5bd123099e2ecde20
child 462077 9cec783aa7645252188a091816539e980c0371a6
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1442363
milestone60.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 1442363, part 5 - Constify XPTInterfaceDescriptor::method_descriptors. r=njn Also, change some reinterpret casts to static casts, because there was no need for them to be reinterpret. MozReview-Commit-ID: EtPmwxboaq9
xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
xpcom/typelib/xpt/xpt_struct.cpp
xpcom/typelib/xpt/xpt_struct.h
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
@@ -80,17 +80,17 @@ xptiInterfaceEntry::ResolveLocked()
             return false;
         }
 
         mParent = parent;
         if (parent->GetHasNotXPCOMFlag()) {
             SetHasNotXPCOMFlag();
         } else {
             for (uint16_t idx = 0; idx < mDescriptor->num_methods; ++idx) {
-                nsXPTMethodInfo* method = reinterpret_cast<nsXPTMethodInfo*>(
+                const nsXPTMethodInfo* method = static_cast<const nsXPTMethodInfo*>(
                     mDescriptor->method_descriptors + idx);
                 if (method->IsNotXPCOM()) {
                     SetHasNotXPCOMFlag();
                     break;
                 }
             }
         }
 
@@ -185,35 +185,34 @@ xptiInterfaceEntry::GetMethodInfo(uint16
                 mDescriptor->num_methods)
     {
         NS_ERROR("bad param");
         *info = nullptr;
         return NS_ERROR_INVALID_ARG;
     }
 
     // else...
-    *info = reinterpret_cast<nsXPTMethodInfo*>
-       (&mDescriptor->method_descriptors[index - mMethodBaseIndex]);
+    *info = static_cast<const nsXPTMethodInfo*>
+        (&mDescriptor->method_descriptors[index - mMethodBaseIndex]);
     return NS_OK;
 }
 
 nsresult
 xptiInterfaceEntry::GetMethodInfoForName(const char* methodName, uint16_t *index,
                                          const nsXPTMethodInfo** result)
 {
     if(!EnsureResolved())
         return NS_ERROR_UNEXPECTED;
 
     // This is a slow algorithm, but this is not expected to be called much.
     for(uint16_t i = 0; i < mDescriptor->num_methods; ++i)
     {
         const nsXPTMethodInfo* info;
-        info = reinterpret_cast<nsXPTMethodInfo*>
-                               (&mDescriptor->
-                                        method_descriptors[i]);
+        info = static_cast<const nsXPTMethodInfo*>
+            (&mDescriptor->method_descriptors[i]);
         if (PL_strcmp(methodName, info->GetName()) == 0) {
             *index = i + mMethodBaseIndex;
             *result = info;
             return NS_OK;
         }
     }
 
     if(mParent)
--- a/xpcom/typelib/xpt/xpt_struct.cpp
+++ b/xpcom/typelib/xpt/xpt_struct.cpp
@@ -254,29 +254,33 @@ DoInterfaceDescriptor(XPTArena *arena, N
         *idp = NULL;
         return true;
     }
     if(!XPT_Do16(cursor, &id->parent_interface) ||
        !XPT_Do16(cursor, &id->num_methods)) {
         return false;
     }
 
+    XPTMethodDescriptor* method_descriptors = nullptr;
+
     if (id->num_methods) {
         size_t n = id->num_methods * sizeof(XPTMethodDescriptor);
-        id->method_descriptors =
+        method_descriptors =
             static_cast<XPTMethodDescriptor*>(XPT_CALLOC8(arena, n));
-        if (!id->method_descriptors)
+        if (!method_descriptors)
             return false;
     }
 
     for (i = 0; i < id->num_methods; i++) {
-        if (!DoMethodDescriptor(arena, cursor, &id->method_descriptors[i], id))
+        if (!DoMethodDescriptor(arena, cursor, &method_descriptors[i], id))
             return false;
     }
 
+    id->method_descriptors = method_descriptors;
+
     if (!XPT_Do16(cursor, &id->num_constants)) {
         return false;
     }
 
     if (id->num_constants) {
         size_t n = id->num_constants * sizeof(XPTConstDescriptor);
         id->const_descriptors =
             static_cast<XPTConstDescriptor*>(XPT_CALLOC8(arena, n));
--- a/xpcom/typelib/xpt/xpt_struct.h
+++ b/xpcom/typelib/xpt/xpt_struct.h
@@ -96,17 +96,17 @@ struct XPTInterfaceDescriptor {
   bool IsBuiltinClass() const { return !!(flags & kBuiltinClassMask); }
   bool IsMainProcessScriptableOnly() const { return !!(flags & kMainProcessScriptableOnlyMask); }
 
   /*
    * This field ordering minimizes the size of this struct.
    * The fields are serialized on disk in a different order.
    * See DoInterfaceDescriptor().
    */
-  XPTMethodDescriptor* method_descriptors;
+  const XPTMethodDescriptor* method_descriptors;
   XPTConstDescriptor* const_descriptors;
   XPTTypeDescriptor* additional_types;
   uint16_t parent_interface;
   uint16_t num_methods;
   uint16_t num_constants;
   uint8_t flags;
 
   /*