diff options
author | Max Kellermann <max@duempel.org> | 2014-01-18 19:24:55 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-18 19:24:55 +0100 |
commit | bc966577ffb2354f44ebb85ceb83b188bb6907b6 (patch) | |
tree | 9a3cf69e7521fb112270818ff8668d312ffc3e28 /src | |
parent | fdf4dff561d637ac7ea29b4438663870bb97839b (diff) | |
download | mpd-bc966577ffb2354f44ebb85ceb83b188bb6907b6.tar.gz mpd-bc966577ffb2354f44ebb85ceb83b188bb6907b6.tar.xz mpd-bc966577ffb2354f44ebb85ceb83b188bb6907b6.zip |
Song: use the VarSize library
Diffstat (limited to 'src')
-rw-r--r-- | src/Song.cxx | 29 | ||||
-rw-r--r-- | src/Song.hxx | 3 |
2 files changed, 19 insertions, 13 deletions
diff --git a/src/Song.cxx b/src/Song.cxx index c80185506..9edbe37f6 100644 --- a/src/Song.cxx +++ b/src/Song.cxx @@ -21,13 +21,24 @@ #include "Song.hxx" #include "Directory.hxx" #include "tag/Tag.hxx" -#include "util/Alloc.hxx" +#include "util/VarSize.hxx" #include "DetachedSong.hxx" #include <assert.h> #include <string.h> #include <stdlib.h> +inline Song::Song(const char *_uri, size_t uri_length, Directory *_parent) + :tag(nullptr), parent(_parent), mtime(0), start_ms(0), end_ms(0) +{ + memcpy(uri, _uri, uri_length + 1); +} + +inline Song::~Song() +{ + delete tag; +} + static Song * song_alloc(const char *uri, Directory *parent) { @@ -37,16 +48,9 @@ song_alloc(const char *uri, Directory *parent) uri_length = strlen(uri); assert(uri_length); - Song *song = (Song *) - xalloc(sizeof(*song) - sizeof(song->uri) + uri_length + 1); - - song->tag = nullptr; - memcpy(song->uri, uri, uri_length + 1); - song->parent = parent; - song->mtime = 0; - song->start_ms = song->end_ms = 0; - - return song; + return NewVarSize<Song>(sizeof(Song::uri), + uri_length + 1, + uri, uri_length, parent); } Song * @@ -69,8 +73,7 @@ Song::NewFile(const char *path, Directory *parent) void Song::Free() { - delete tag; - free(this); + DeleteVarSize(this); } std::string diff --git a/src/Song.hxx b/src/Song.hxx index d3f762df4..2dadd85cb 100644 --- a/src/Song.hxx +++ b/src/Song.hxx @@ -77,6 +77,9 @@ struct Song { */ char uri[sizeof(int)]; + Song(const char *_uri, size_t uri_length, Directory *parent); + ~Song(); + gcc_malloc static Song *NewFrom(DetachedSong &&other, Directory *parent); |