aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-16 19:11:39 +0200
committerMax Kellermann <max@duempel.org>2008-09-16 19:11:39 +0200
commit9e94b7cb6eebcf40d2508cc365dbc7c221071454 (patch)
treef934b1478c805df268c50bb80f698f1475986aa0 /src
parentac9b642dde4c63f35936d19ed937481bc73f8db4 (diff)
downloadmpd-9e94b7cb6eebcf40d2508cc365dbc7c221071454.tar.gz
mpd-9e94b7cb6eebcf40d2508cc365dbc7c221071454.tar.xz
mpd-9e94b7cb6eebcf40d2508cc365dbc7c221071454.zip
song: allocate mpd_song from glib slices
Since we compile ncmpc with glib, we can use its slice allocator for efficient song allocation. I have added a way to disable this with a macro.
Diffstat (limited to '')
-rw-r--r--src/song.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/song.c b/src/song.c
index 9090f8489..ab79653de 100644
--- a/src/song.c
+++ b/src/song.c
@@ -33,7 +33,13 @@
#include "song.h"
#include "str_pool.h"
+#define LIBMPDCLIENT_GLIB_SLICE
+
+#ifndef LIBMPDCLIENT_GLIB_SLICE
#include <stdlib.h>
+#else
+#include <glib.h>
+#endif
static void mpd_initSong(struct mpd_song *song) {
song->file = NULL;
@@ -80,7 +86,11 @@ static void mpd_finishSong(struct mpd_song *song) {
}
struct mpd_song *mpd_newSong(void) {
+#ifndef LIBMPDCLIENT_GLIB_SLICE
struct mpd_song *ret = malloc(sizeof(*ret));
+#else
+ struct mpd_song *ret = g_slice_new(struct mpd_song);
+#endif
mpd_initSong(ret);
@@ -89,7 +99,12 @@ struct mpd_song *mpd_newSong(void) {
void mpd_freeSong(struct mpd_song *song) {
mpd_finishSong(song);
+
+#ifndef LIBMPDCLIENT_GLIB_SLICE
free(song);
+#else
+ g_slice_free(struct mpd_song, song);
+#endif
}
struct mpd_song *mpd_songDup(const struct mpd_song *song) {