summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/PlaylistFile.cxx3
-rw-r--r--src/SongLoader.cxx14
-rw-r--r--src/SongLoader.hxx8
-rw-r--r--src/command/QueueCommands.cxx6
-rw-r--r--src/playlist/PlaylistSong.cxx24
-rw-r--r--src/queue/PlaylistEdit.cxx3
6 files changed, 23 insertions, 35 deletions
diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx
index 2deae4321..d9846044e 100644
--- a/src/PlaylistFile.cxx
+++ b/src/PlaylistFile.cxx
@@ -359,8 +359,7 @@ void
spl_append_uri(const char *utf8file,
const SongLoader &loader, const char *url)
{
- std::unique_ptr<DetachedSong> song(loader.LoadSong(url));
- spl_append_song(utf8file, *song);
+ spl_append_song(utf8file, loader.LoadSong(url));
}
static void
diff --git a/src/SongLoader.cxx b/src/SongLoader.cxx
index 04940cd53..7d03ff075 100644
--- a/src/SongLoader.cxx
+++ b/src/SongLoader.cxx
@@ -36,12 +36,12 @@ SongLoader::SongLoader(const Client &_client)
#endif
-DetachedSong *
+DetachedSong
SongLoader::LoadFromDatabase(const char *uri) const
{
#ifdef ENABLE_DATABASE
if (db != nullptr)
- return new DetachedSong(DatabaseDetachSong(*db, *storage, uri));
+ return DatabaseDetachSong(*db, *storage, uri);
#else
(void)uri;
#endif
@@ -49,7 +49,7 @@ SongLoader::LoadFromDatabase(const char *uri) const
throw PlaylistError(PlaylistResult::NO_SUCH_SONG, "No database");
}
-DetachedSong *
+DetachedSong
SongLoader::LoadFile(const char *path_utf8, Path path_fs) const
{
#ifdef ENABLE_DATABASE
@@ -66,15 +66,15 @@ SongLoader::LoadFile(const char *path_utf8, Path path_fs) const
if (!song.LoadFile(path_fs))
throw PlaylistError::NoSuchSong();
- return new DetachedSong(std::move(song));
+ return song;
}
-DetachedSong *
+DetachedSong
SongLoader::LoadSong(const LocatedUri &located_uri) const
{
switch (located_uri.type) {
case LocatedUri::Type::ABSOLUTE:
- return new DetachedSong(located_uri.canonical_uri);
+ return DetachedSong(located_uri.canonical_uri);
case LocatedUri::Type::RELATIVE:
return LoadFromDatabase(located_uri.canonical_uri);
@@ -86,7 +86,7 @@ SongLoader::LoadSong(const LocatedUri &located_uri) const
gcc_unreachable();
}
-DetachedSong *
+DetachedSong
SongLoader::LoadSong(const char *uri_utf8) const
{
#if !CLANG_CHECK_VERSION(3,6)
diff --git a/src/SongLoader.hxx b/src/SongLoader.hxx
index 686a2978d..ffb337ab9 100644
--- a/src/SongLoader.hxx
+++ b/src/SongLoader.hxx
@@ -67,20 +67,20 @@ public:
}
#endif
- DetachedSong *LoadSong(const LocatedUri &uri) const;
+ DetachedSong LoadSong(const LocatedUri &uri) const;
/**
* Throws #std::runtime_error on error.
*/
gcc_nonnull_all
- DetachedSong *LoadSong(const char *uri_utf8) const;
+ DetachedSong LoadSong(const char *uri_utf8) const;
private:
gcc_nonnull_all
- DetachedSong *LoadFromDatabase(const char *uri) const;
+ DetachedSong LoadFromDatabase(const char *uri) const;
gcc_nonnull_all
- DetachedSong *LoadFile(const char *path_utf8, Path path_fs) const;
+ DetachedSong LoadFile(const char *path_utf8, Path path_fs) const;
};
#endif
diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx
index 52faf1d35..0d43f66b5 100644
--- a/src/command/QueueCommands.cxx
+++ b/src/command/QueueCommands.cxx
@@ -43,11 +43,9 @@
static void
AddUri(Client &client, const LocatedUri &uri)
{
- std::unique_ptr<DetachedSong> song(SongLoader(client).LoadSong(uri));
- assert(song);
-
auto &partition = client.partition;
- partition.playlist.AppendSong(partition.pc, std::move(*song));
+ partition.playlist.AppendSong(partition.pc,
+ SongLoader(client).LoadSong(uri));
}
static CommandResult
diff --git a/src/playlist/PlaylistSong.cxx b/src/playlist/PlaylistSong.cxx
index ae18b1b67..12cd4bdb0 100644
--- a/src/playlist/PlaylistSong.cxx
+++ b/src/playlist/PlaylistSong.cxx
@@ -44,25 +44,17 @@ merge_song_metadata(DetachedSong &add, const DetachedSong &base)
static bool
playlist_check_load_song(DetachedSong &song, const SongLoader &loader)
-{
- DetachedSong *tmp;
-
- try {
- tmp = loader.LoadSong(song.GetURI());
- } catch (const std::runtime_error &) {
- return false;
- }
-
- if (tmp == nullptr)
- return false;
+try {
+ DetachedSong tmp = loader.LoadSong(song.GetURI());
- song.SetURI(tmp->GetURI());
- if (!song.HasRealURI() && tmp->HasRealURI())
- song.SetRealURI(tmp->GetRealURI());
+ song.SetURI(tmp.GetURI());
+ if (!song.HasRealURI() && tmp.HasRealURI())
+ song.SetRealURI(tmp.GetRealURI());
- merge_song_metadata(song, *tmp);
- delete tmp;
+ merge_song_metadata(song, tmp);
return true;
+} catch (const std::runtime_error &) {
+ return false;
}
bool
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index 67675680c..a4a1a29e2 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -125,8 +125,7 @@ unsigned
playlist::AppendURI(PlayerControl &pc, const SongLoader &loader,
const char *uri)
{
- std::unique_ptr<DetachedSong> song(loader.LoadSong(uri));
- return AppendSong(pc, std::move(*song));
+ return AppendSong(pc, loader.LoadSong(uri));
}
void