Bug 1439770, part 2 - Inline constant argument to InterfaceDescriptorAddTypes. r=njn draft
authorAndrew McCreight <continuation@gmail.com>
Tue, 20 Feb 2018 13:38:38 -0800
changeset 757636 b25f9d01202bf50b3adb33bb989c0a2eedabbaf8
parent 757635 94d3ce7cccced5dde40f08aadb22048824ab8ff2
push id99813
push userbmo:continuation@gmail.com
push dateTue, 20 Feb 2018 23:22:53 +0000
reviewersnjn
bugs1439770
milestone60.0a1
Bug 1439770, part 2 - Inline constant argument to InterfaceDescriptorAddTypes. r=njn MozReview-Commit-ID: 4mCgB5NFife
xpcom/typelib/xpt/xpt_struct.cpp
--- a/xpcom/typelib/xpt/xpt_struct.cpp
+++ b/xpcom/typelib/xpt/xpt_struct.cpp
@@ -166,37 +166,36 @@ DoInterfaceDirectoryEntry(XPTArena *aren
         !DoInterfaceDescriptor(arena, cursor, &ide->interface_descriptor)) {
         return false;
     }
 
     return true;
 }
 
 static bool
-InterfaceDescriptorAddTypes(XPTArena *arena, XPTInterfaceDescriptor *id,
-                            uint16_t num)
+InterfaceDescriptorAddType(XPTArena *arena, XPTInterfaceDescriptor *id)
 {
     XPTTypeDescriptor *old = id->additional_types;
     XPTTypeDescriptor *new_;
     size_t old_size = id->num_additional_types * sizeof(XPTTypeDescriptor);
-    size_t new_size = (num * sizeof(XPTTypeDescriptor)) + old_size;
+    size_t new_size = old_size + sizeof(XPTTypeDescriptor);
 
     /* XXX should grow in chunks to minimize alloc overhead */
     new_ = static_cast<XPTTypeDescriptor*>(XPT_CALLOC8(arena, new_size));
     if (!new_)
         return false;
     if (old) {
         memcpy(new_, old, old_size);
     }
     id->additional_types = new_;
 
-    if (num + uint16_t(id->num_additional_types) > UINT8_MAX)
+    if (id->num_additional_types == UINT8_MAX)
         return false;
 
-    id->num_additional_types += num;
+    id->num_additional_types += 1;
     return true;
 }
 
 bool
 DoInterfaceDescriptor(XPTArena *arena, NotNull<XPTCursor*> outer,
                       XPTInterfaceDescriptor **idp)
 {
     XPTInterfaceDescriptor *id;
@@ -383,17 +382,17 @@ DoTypeDescriptor(XPTArena *arena, NotNul
         break;
       case TD_ARRAY: {
         // argnum2 appears in the on-disk format but it isn't used.
         uint8_t argnum2 = 0;
         if (!XPT_Do8(cursor, &td->u.array.argnum) ||
             !XPT_Do8(cursor, &argnum2))
             return false;
 
-        if (!InterfaceDescriptorAddTypes(arena, id, 1))
+        if (!InterfaceDescriptorAddType(arena, id))
             return false;
         td->u.array.additional_type = id->num_additional_types - 1;
 
         if (!DoTypeDescriptor(arena, cursor,
                               &id->additional_types[td->u.array.additional_type],
                               id))
             return false;
         break;