diff --git a/glib/gslice.h b/glib/gslice.h index ff8b02a65..002410635 100644 --- a/glib/gslice.h +++ b/glib/gslice.h @@ -23,6 +23,7 @@ #endif #include +#include G_BEGIN_DECLS @@ -43,7 +44,22 @@ void g_slice_free_chain_with_offset (gsize block_size, gpointer mem_chain, gsize next_offset); #define g_slice_new(type) ((type*) g_slice_alloc (sizeof (type))) -#define g_slice_new0(type) ((type*) g_slice_alloc0 (sizeof (type))) + +/* Allow the compiler to inline memset(). Since the size is a constant, this + * can significantly improve performance. */ +#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__) +# define g_slice_new0(type) \ + (type *) (G_GNUC_EXTENSION ({ \ + gsize __s = sizeof (type); \ + gpointer __p; \ + __p = g_slice_alloc (__s); \ + memset (__p, 0, __s); \ + __p; \ + })) +#else +# define g_slice_new0(type) ((type*) g_slice_alloc0 (sizeof (type))) +#endif + /* MemoryBlockType * * g_slice_dup (MemoryBlockType, * MemoryBlockType *mem_block);