Song: use the VarSize library
This commit is contained in:
parent
fdf4dff561
commit
bc966577ff
29
src/Song.cxx
29
src/Song.cxx
|
@ -21,13 +21,24 @@
|
||||||
#include "Song.hxx"
|
#include "Song.hxx"
|
||||||
#include "Directory.hxx"
|
#include "Directory.hxx"
|
||||||
#include "tag/Tag.hxx"
|
#include "tag/Tag.hxx"
|
||||||
#include "util/Alloc.hxx"
|
#include "util/VarSize.hxx"
|
||||||
#include "DetachedSong.hxx"
|
#include "DetachedSong.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.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 *
|
static Song *
|
||||||
song_alloc(const char *uri, Directory *parent)
|
song_alloc(const char *uri, Directory *parent)
|
||||||
{
|
{
|
||||||
|
@ -37,16 +48,9 @@ song_alloc(const char *uri, Directory *parent)
|
||||||
uri_length = strlen(uri);
|
uri_length = strlen(uri);
|
||||||
assert(uri_length);
|
assert(uri_length);
|
||||||
|
|
||||||
Song *song = (Song *)
|
return NewVarSize<Song>(sizeof(Song::uri),
|
||||||
xalloc(sizeof(*song) - sizeof(song->uri) + uri_length + 1);
|
uri_length + 1,
|
||||||
|
uri, uri_length, parent);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Song *
|
Song *
|
||||||
|
@ -69,8 +73,7 @@ Song::NewFile(const char *path, Directory *parent)
|
||||||
void
|
void
|
||||||
Song::Free()
|
Song::Free()
|
||||||
{
|
{
|
||||||
delete tag;
|
DeleteVarSize(this);
|
||||||
free(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
|
|
@ -77,6 +77,9 @@ struct Song {
|
||||||
*/
|
*/
|
||||||
char uri[sizeof(int)];
|
char uri[sizeof(int)];
|
||||||
|
|
||||||
|
Song(const char *_uri, size_t uri_length, Directory *parent);
|
||||||
|
~Song();
|
||||||
|
|
||||||
gcc_malloc
|
gcc_malloc
|
||||||
static Song *NewFrom(DetachedSong &&other, Directory *parent);
|
static Song *NewFrom(DetachedSong &&other, Directory *parent);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue