Merge branch 'wip/alloc-memset-inlining' into 'master'

gslice: Allow inlining of memset() in g_slice_new0() macro

Closes #5

See merge request GNOME/glib!1597
This commit is contained in:
Philip Withnall 2020-08-12 13:29:27 +00:00
commit d31c771185

View File

@ -23,6 +23,7 @@
#endif
#include <glib/gtypes.h>
#include <string.h>
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);