diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-06 18:46:52 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-06 18:46:52 +0200 |
commit | 267b2cd6e668fb380a53b1377143a5cc7ce949ea (patch) | |
tree | a1cea3d612df1e029f7ffb87b46f28b36a0a2d22 /src/song.c | |
parent | 43761441c9bbb763ccde3ae2f7f5508f5cec70ec (diff) | |
download | mpd-267b2cd6e668fb380a53b1377143a5cc7ce949ea.tar.gz mpd-267b2cd6e668fb380a53b1377143a5cc7ce949ea.tar.xz mpd-267b2cd6e668fb380a53b1377143a5cc7ce949ea.zip |
song: use flex arrays to store song->url
Reduce the number of allocations we make, so there's less
pressure on the allocator and less overhead to keep track
of the allocations in.
Diffstat (limited to 'src/song.c')
-rw-r--r-- | src/song.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/song.c b/src/song.c index 75dd0257f..3081dec4e 100644 --- a/src/song.c +++ b/src/song.c @@ -28,6 +28,19 @@ #include "os_compat.h" +Song * +song_alloc(const char *url, enum song_type type, struct _Directory *parent) +{ + size_t urllen = strlen(url); + Song *song = xmalloc(sizeof(Song) + urllen); + + song->tag = NULL; + memcpy(song->url, url, urllen + 1); + song->type = type; + song->parentDir = parent; + + return song; +} Song *newSong(const char *url, enum song_type type, Directory * parentDir) { @@ -38,11 +51,7 @@ Song *newSong(const char *url, enum song_type type, Directory * parentDir) return NULL; } - song = xmalloc(sizeof(*song)); - song->tag = NULL; - song->url = xstrdup(url); - song->type = type; - song->parentDir = parentDir; + song = song_alloc(url, type, parentDir); assert(type == SONG_TYPE_URL || parentDir); @@ -75,7 +84,6 @@ void freeSong(Song * song) void freeJustSong(Song * song) { - free(song->url); if (song->tag) tag_free(song->tag); free(song); @@ -114,7 +122,7 @@ char *get_song_url(char *path_max_tmp, Song *song) if (!song) return NULL; - assert(song->url != NULL); + assert(*song->url); if (!song->parentDir || !song->parentDir->path) strcpy(path_max_tmp, song->url); |