PlaylistSong: pass reference variables internally

This commit is contained in:
Max Kellermann 2014-01-20 19:50:19 +01:00
parent 2f51285349
commit 07a3bef25c
1 changed files with 17 additions and 18 deletions

View File

@ -34,30 +34,29 @@
#include <string.h> #include <string.h>
static void static void
merge_song_metadata(DetachedSong *dest, const DetachedSong *base, merge_song_metadata(DetachedSong &dest, const DetachedSong &base,
const DetachedSong *add) const DetachedSong &add)
{ {
{ {
TagBuilder builder(add->GetTag()); TagBuilder builder(add.GetTag());
builder.Complement(base->GetTag()); builder.Complement(base.GetTag());
dest->SetTag(builder.Commit()); dest.SetTag(builder.Commit());
} }
dest->SetLastModified(base->GetLastModified()); dest.SetLastModified(base.GetLastModified());
dest->SetStartMS(add->GetStartMS()); dest.SetStartMS(add.GetStartMS());
dest->SetEndMS(add->GetEndMS()); dest.SetEndMS(add.GetEndMS());
} }
static DetachedSong * static DetachedSong *
apply_song_metadata(DetachedSong *dest, const DetachedSong *src) apply_song_metadata(DetachedSong *dest, const DetachedSong &src)
{ {
DetachedSong *tmp; DetachedSong *tmp;
assert(dest != nullptr); assert(dest != nullptr);
assert(src != nullptr);
if (!src->GetTag().IsDefined() && if (!src.GetTag().IsDefined() &&
src->GetStartMS() == 0 && src->GetEndMS() == 0) src.GetStartMS() == 0 && src.GetEndMS() == 0)
return dest; return dest;
if (dest->IsInDatabase()) { if (dest->IsInDatabase()) {
@ -71,20 +70,20 @@ apply_song_metadata(DetachedSong *dest, const DetachedSong *src)
tmp = new DetachedSong(std::move(path_utf8)); tmp = new DetachedSong(std::move(path_utf8));
merge_song_metadata(tmp, dest, src); merge_song_metadata(*tmp, *dest, src);
} else { } else {
tmp = new DetachedSong(dest->GetURI()); tmp = new DetachedSong(dest->GetURI());
merge_song_metadata(tmp, dest, src); merge_song_metadata(*tmp, *dest, src);
} }
if (dest->GetTag().IsDefined() && dest->GetTag().time > 0 && if (dest->GetTag().IsDefined() && dest->GetTag().time > 0 &&
src->GetStartMS() > 0 && src->GetEndMS() == 0 && src.GetStartMS() > 0 && src.GetEndMS() == 0 &&
src->GetStartMS() / 1000 < (unsigned)dest->GetTag().time) src.GetStartMS() / 1000 < (unsigned)dest->GetTag().time)
/* the range is open-ended, and the playlist plugin /* the range is open-ended, and the playlist plugin
did not know the total length of the song file did not know the total length of the song file
(e.g. last track on a CUE file); fix it up here */ (e.g. last track on a CUE file); fix it up here */
tmp->WritableTag().time = tmp->WritableTag().time =
dest->GetTag().time - src->GetStartMS() / 1000; dest->GetTag().time - src.GetStartMS() / 1000;
delete dest; delete dest;
return tmp; return tmp;
@ -109,7 +108,7 @@ playlist_check_load_song(const DetachedSong *song, const char *uri, bool secure)
return nullptr; return nullptr;
} }
return apply_song_metadata(dest, song); return apply_song_metadata(dest, *song);
} }
DetachedSong * DetachedSong *