Bug 1402174 - Merge imalloc and icalloc into a single function. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 21 Sep 2017 13:23:22 +0900
changeset 669298 099402c1553a03a1cbae25e1fa461895cbb09af7
parent 669297 ef67698e912570cf64ae77065f4eabda9b3fd7aa
child 669299 16cd277ea46c6846d48a456c493ed7c56f880a9e
push id81294
push userbmo:mh+mozilla@glandium.org
push dateFri, 22 Sep 2017 21:53:13 +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;