db/simple/Song: convert NewFrom() to constructor

This commit is contained in:
Max Kellermann 2019-09-04 11:36:33 +02:00
parent 497d090814
commit 949916cba1
4 changed files with 12 additions and 18 deletions

View File

@ -165,8 +165,8 @@ directory_load(TextFile &file, Directory &directory)
auto detached_song = song_load(file, name, auto detached_song = song_load(file, name,
&audio_format); &audio_format);
auto song = Song::NewFrom(std::move(*detached_song), auto song = std::make_unique<Song>(std::move(*detached_song),
directory); directory);
song->audio_format = audio_format; song->audio_format = audio_format;
directory.AddSong(std::move(song)); directory.AddSong(std::move(song));

View File

@ -31,21 +31,14 @@ Song::Song(StringView _uri, Directory &_parent) noexcept
{ {
} }
static SongPtr Song::Song(DetachedSong &&other, Directory &_parent) noexcept
song_alloc(StringView uri, Directory &parent) noexcept :tag(std::move(other.WritableTag())),
parent(_parent),
mtime(other.GetLastModified()),
start_time(other.GetStartTime()),
end_time(other.GetEndTime()),
uri(other.GetURI())
{ {
return std::make_unique<Song>(uri, parent);
}
SongPtr
Song::NewFrom(DetachedSong &&other, Directory &parent) noexcept
{
SongPtr song(song_alloc(other.GetURI(), parent));
song->tag = std::move(other.WritableTag());
song->mtime = other.GetLastModified();
song->start_time = other.GetStartTime();
song->end_time = other.GetEndTime();
return song;
} }
std::string std::string

View File

@ -99,7 +99,7 @@ struct Song {
Song(StringView _uri, Directory &parent) noexcept; Song(StringView _uri, Directory &parent) noexcept;
static SongPtr NewFrom(DetachedSong &&other, Directory &parent) noexcept; Song(DetachedSong &&other, Directory &_parent) noexcept;
/** /**
* allocate a new song structure with a local file name and attempt to * allocate a new song structure with a local file name and attempt to

View File

@ -69,7 +69,8 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
} }
for (auto &vtrack : v) { for (auto &vtrack : v) {
auto song = Song::NewFrom(std::move(vtrack), *contdir); auto song = std::make_unique<Song>(std::move(vtrack),
*contdir);
// shouldn't be necessary but it's there.. // shouldn't be necessary but it's there..
song->mtime = info.mtime; song->mtime = info.mtime;