Bug 1402174 - Merge imalloc and icalloc into a single function. r?njn
--- 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;