Bug 1402174 - Merge imalloc and icalloc into a single function. r=njn
☠☠ backed out by 59fe562e84ff ☠ ☠
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 21 Sep 2017 13:23:22 +0900
changeset 669087 5bba0584a7d88d05269794860237428ece4badd1
parent 669086 14dac365b5f6e32b3caab3ab4bd2a75856374c72
child 669088 e356ac32e2978d2631f771ab270309f9e5f2ca65
push id81210
push userkgupta@mozilla.com
push dateFri, 22 Sep 2017 14:09:59 +0000
reviewersnjn
bugs1402174
milestone58.0a1
Bug 1402174 - Merge imalloc and icalloc into a single function. r=njn
memory/build/mozjemalloc.cpp
--- a/memory/build/mozjemalloc.cpp
+++ b/memory/build/mozjemalloc.cpp
@@ -3329,36 +3329,25 @@ arena_t::Malloc(size_t aSize, bool aZero
   MOZ_DIAGNOSTIC_ASSERT(mMagic == ARENA_MAGIC);
   MOZ_ASSERT(aSize != 0);
   MOZ_ASSERT(QUANTUM_CEILING(aSize) <= arena_maxclass);
 
   return (aSize <= bin_maxclass) ? MallocSmall(aSize, aZero)
                                  : MallocLarge(aSize, aZero);
 }
 
-static inline void *
-imalloc(size_t size)
+static inline void*
+imalloc(size_t aSize, bool aZero)
 {
-
-	MOZ_ASSERT(size != 0);
-
-	if (size <= arena_maxclass)
-		return choose_arena(size)->Malloc(size, false);
-	else
-		return (huge_malloc(size, false));
-}
-
-static inline void *
-icalloc(size_t size)
-{
-
-	if (size <= arena_maxclass)
-		return choose_arena(size)->Malloc(size, true);
-	else
-		return (huge_malloc(size, true));
+  MOZ_ASSERT(aSize != 0);
+
+  if (aSize <= arena_maxclass) {
+    return choose_arena(aSize)->Malloc(aSize, aZero);
+  }
+  return huge_malloc(aSize, aZero);
 }
 
 /* Only handles large allocations that require more than page alignment. */
 void*
 arena_t::Palloc(size_t aAlignment, size_t aSize, size_t aAllocSize)
 {
   void* ret;
   size_t offset;
@@ -4687,17 +4676,17 @@ MozJemalloc::malloc(size_t aSize)
     ret = nullptr;
     goto RETURN;
   }
 
   if (aSize == 0) {
     aSize = 1;
   }
 
-  ret = imalloc(aSize);
+  ret = imalloc(aSize, /* zero = */ false);
 
 RETURN:
   if (!ret) {
     errno = ENOMEM;
   }
 
   return ret;
 }
@@ -4745,17 +4734,17 @@ MozJemalloc::calloc(size_t aNum, size_t 
    */
   } else if (((aNum | aSize) & (SIZE_T_MAX << (sizeof(size_t) << 2)))
       && (num_size / aSize != aNum)) {
     /* size_t overflow. */
     ret = nullptr;
     goto RETURN;
   }
 
-  ret = icalloc(num_size);
+  ret = imalloc(num_size, /* zero = */ true);
 
 RETURN:
   if (!ret) {
     errno = ENOMEM;
   }
 
   return ret;
 }
@@ -4776,17 +4765,17 @@ MozJemalloc::realloc(void* aPtr, size_t 
 
     if (!ret) {
       errno = ENOMEM;
     }
   } else {
     if (malloc_init()) {
       ret = nullptr;
     } else {
-      ret = imalloc(aSize);
+      ret = imalloc(aSize, /* zero = */ false);
     }
 
     if (!ret) {
       errno = ENOMEM;
     }
   }
 
   return ret;