aboutsummaryrefslogtreecommitdiffstats
path: root/src/PlaylistTag.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-07 21:39:47 +0100
committerMax Kellermann <max@duempel.org>2014-01-09 09:05:58 +0100
commit322b0616322760dc162447563d8f4da7e024ca90 (patch)
tree2f87cb3ce061556161797aba9f57ee08de5b9e21 /src/PlaylistTag.cxx
parent43847f2244a34064af24704aac4cfad4a3c76f7d (diff)
downloadmpd-322b0616322760dc162447563d8f4da7e024ca90.tar.gz
mpd-322b0616322760dc162447563d8f4da7e024ca90.tar.xz
mpd-322b0616322760dc162447563d8f4da7e024ca90.zip
DetachedSong: fork of struct Song
From now on, struct Song will be used by the database only, and DetachedSong will be used by everybody else. DetachedSong is easier to use, but Song has lower overhead.
Diffstat (limited to 'src/PlaylistTag.cxx')
-rw-r--r--src/PlaylistTag.cxx36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/PlaylistTag.cxx b/src/PlaylistTag.cxx
index 2897f3252..672111ea5 100644
--- a/src/PlaylistTag.cxx
+++ b/src/PlaylistTag.cxx
@@ -26,7 +26,7 @@
#include "config.h"
#include "Playlist.hxx"
#include "PlaylistError.hxx"
-#include "Song.hxx"
+#include "DetachedSong.hxx"
#include "tag/Tag.hxx"
#include "tag/TagBuilder.hxx"
#include "util/Error.hxx"
@@ -42,22 +42,19 @@ playlist::AddSongIdTag(unsigned id, TagType tag_type, const char *value,
return false;
}
- Song &song = queue.Get(position);
+ DetachedSong &song = queue.Get(position);
if (song.IsFile()) {
error.Set(playlist_domain, int(PlaylistResult::DENIED),
"Cannot edit tags of local file");
return false;
}
- TagBuilder tag;
- if (song.tag != nullptr) {
- tag = std::move(*song.tag);
- delete song.tag;
+ {
+ TagBuilder tag(std::move(song.WritableTag()));
+ tag.AddItem(tag_type, value);
+ song.SetTag(tag.Commit());
}
- tag.AddItem(tag_type, value);
- song.tag = tag.CommitNew();
-
queue.ModifyAtPosition(position);
OnModified();
return true;
@@ -74,24 +71,21 @@ playlist::ClearSongIdTag(unsigned id, TagType tag_type,
return false;
}
- Song &song = queue.Get(position);
+ DetachedSong &song = queue.Get(position);
if (song.IsFile()) {
error.Set(playlist_domain, int(PlaylistResult::DENIED),
"Cannot edit tags of local file");
return false;
}
- if (song.tag == nullptr)
- return true;
-
- TagBuilder tag(std::move(*song.tag));
- delete song.tag;
-
- if (tag_type == TAG_NUM_OF_ITEM_TYPES)
- tag.RemoveAll();
- else
- tag.RemoveType(tag_type);
- song.tag = tag.CommitNew();
+ {
+ TagBuilder tag(std::move(song.WritableTag()));
+ if (tag_type == TAG_NUM_OF_ITEM_TYPES)
+ tag.RemoveAll();
+ else
+ tag.RemoveType(tag_type);
+ song.SetTag(tag.Commit());
+ }
queue.ModifyAtPosition(position);
OnModified();