diff options
author | Max Kellermann <max@duempel.org> | 2014-01-18 19:08:39 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-19 02:58:55 +0100 |
commit | d2cf74027c2c252181ab16c1348281c252665353 (patch) | |
tree | 50dc8efe859419ad9f266bc277049bae34790c78 /src/Song.cxx | |
parent | bc966577ffb2354f44ebb85ceb83b188bb6907b6 (diff) | |
download | mpd-d2cf74027c2c252181ab16c1348281c252665353.tar.gz mpd-d2cf74027c2c252181ab16c1348281c252665353.tar.xz mpd-d2cf74027c2c252181ab16c1348281c252665353.zip |
Song: embed the Tag object statically into class Song
Reduces overhead because we need to manage only one memory allocation.
According to valgrind/massif, we save 7%.
Diffstat (limited to 'src/Song.cxx')
-rw-r--r-- | src/Song.cxx | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/Song.cxx b/src/Song.cxx index 9edbe37f6..384307642 100644 --- a/src/Song.cxx +++ b/src/Song.cxx @@ -29,14 +29,13 @@ #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) + :parent(_parent), mtime(0), start_ms(0), end_ms(0) { memcpy(uri, _uri, uri_length + 1); } inline Song::~Song() { - delete tag; } static Song * @@ -57,7 +56,7 @@ Song * Song::NewFrom(DetachedSong &&other, Directory *parent) { Song *song = song_alloc(other.GetURI(), parent); - song->tag = new Tag(std::move(other.WritableTag())); + song->tag = std::move(other.WritableTag()); song->mtime = other.GetLastModified(); song->start_ms = other.GetStartMS(); song->end_ms = other.GetEndMS(); @@ -101,8 +100,8 @@ Song::GetDuration() const if (end_ms > 0) return (end_ms - start_ms) / 1000.0; - if (tag == nullptr) + if (tag.time <= 0) return 0; - return tag->time - start_ms / 1000.0; + return tag.time - start_ms / 1000.0; } |