|
@@ -45,9 +45,11 @@ malloc (size_t size)
|
|
|
|
|
|
__malloc_lock ();
|
|
__malloc_lock ();
|
|
|
|
|
|
|
|
+ /* First try to get memory that's already in our heap. */
|
|
mem = __heap_alloc (heap, &size);
|
|
mem = __heap_alloc (heap, &size);
|
|
- if (! mem)
|
|
|
|
- /* We couldn't allocate from the heap, so get some more memory
|
|
|
|
|
|
+
|
|
|
|
+ if (__malloc_unlikely (! mem))
|
|
|
|
+ /* We couldn't allocate from the heap, so grab some more
|
|
from the system, add it to the heap, and try again. */
|
|
from the system, add it to the heap, and try again. */
|
|
{
|
|
{
|
|
/* If we're trying to allocate a block bigger than the default
|
|
/* If we're trying to allocate a block bigger than the default
|
|
@@ -74,7 +76,7 @@ malloc (size_t size)
|
|
/* Use sbrk we can, as it's faster than mmap, and guarantees
|
|
/* Use sbrk we can, as it's faster than mmap, and guarantees
|
|
contiguous allocation. */
|
|
contiguous allocation. */
|
|
block = sbrk (block_size);
|
|
block = sbrk (block_size);
|
|
- if (block != (void *)-1)
|
|
|
|
|
|
+ if (__malloc_likely (block != (void *)-1))
|
|
{
|
|
{
|
|
/* Because sbrk can return results of arbitrary
|
|
/* Because sbrk can return results of arbitrary
|
|
alignment, align the result to a MALLOC_ALIGNMENT boundary. */
|
|
alignment, align the result to a MALLOC_ALIGNMENT boundary. */
|
|
@@ -103,7 +105,7 @@ malloc (size_t size)
|
|
/* Get back the main lock. */
|
|
/* Get back the main lock. */
|
|
__malloc_lock ();
|
|
__malloc_lock ();
|
|
|
|
|
|
- if (block != (void *)-1)
|
|
|
|
|
|
+ if (__malloc_likely (block != (void *)-1))
|
|
{
|
|
{
|
|
MALLOC_DEBUG (" adding memory: 0x%lx - 0x%lx (%d bytes)\n",
|
|
MALLOC_DEBUG (" adding memory: 0x%lx - 0x%lx (%d bytes)\n",
|
|
(long)block, (long)block + block_size, block_size);
|
|
(long)block, (long)block + block_size, block_size);
|
|
@@ -118,7 +120,7 @@ malloc (size_t size)
|
|
|
|
|
|
__malloc_unlock ();
|
|
__malloc_unlock ();
|
|
|
|
|
|
- if (mem)
|
|
|
|
|
|
+ if (__malloc_likely (mem))
|
|
/* Record the size of this block. */
|
|
/* Record the size of this block. */
|
|
{
|
|
{
|
|
mem = MALLOC_ADDR (mem);
|
|
mem = MALLOC_ADDR (mem);
|