SongSave: return DetachedSong, not a std::unique_ptr<>

Eliminate unnecessary dynamic allocations.
This commit is contained in:
Max Kellermann 2019-09-05 20:50:00 +02:00
parent a1e2602c3d
commit 07f212c98c
4 changed files with 12 additions and 12 deletions

View File

@ -81,11 +81,11 @@ song_save(BufferedOutputStream &os, const DetachedSong &song)
os.Format(SONG_END "\n");
}
std::unique_ptr<DetachedSong>
DetachedSong
song_load(TextFile &file, const char *uri,
AudioFormat *audio_format_r)
{
auto song = std::make_unique<DetachedSong>(uri);
DetachedSong song(uri);
TagBuilder tag;
@ -117,7 +117,7 @@ song_load(TextFile &file, const char *uri,
} else if (StringIsEqual(line, "Playlist")) {
tag.SetHasPlaylist(StringIsEqual(value, "yes"));
} else if (StringIsEqual(line, SONG_MTIME)) {
song->SetLastModified(std::chrono::system_clock::from_time_t(atoi(value)));
song.SetLastModified(std::chrono::system_clock::from_time_t(atoi(value)));
} else if (StringIsEqual(line, "Range")) {
char *endptr;
@ -126,13 +126,13 @@ song_load(TextFile &file, const char *uri,
? strtoul(endptr + 1, nullptr, 10)
: 0;
song->SetStartTime(SongTime::FromMS(start_ms));
song->SetEndTime(SongTime::FromMS(end_ms));
song.SetStartTime(SongTime::FromMS(start_ms));
song.SetEndTime(SongTime::FromMS(end_ms));
} else {
throw FormatRuntimeError("unknown line in db: %s", line);
}
}
song->SetTag(tag.Commit());
song.SetTag(tag.Commit());
return song;
}

View File

@ -42,7 +42,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song);
*
* Throws on error.
*/
std::unique_ptr<DetachedSong>
DetachedSong
song_load(TextFile &file, const char *uri,
AudioFormat *audio_format_r=nullptr);

View File

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

View File

@ -73,7 +73,7 @@ queue_save(BufferedOutputStream &os, const Queue &queue)
}
}
static std::unique_ptr<DetachedSong>
static DetachedSong
LoadQueueSong(TextFile &file, const char *line)
{
std::unique_ptr<DetachedSong> song;
@ -89,7 +89,7 @@ LoadQueueSong(TextFile &file, const char *line)
const char *uri = endptr + 1;
return std::make_unique<DetachedSong>(uri);
return DetachedSong(uri);
}
}
@ -112,8 +112,8 @@ queue_load_song(TextFile &file, const SongLoader &loader,
auto song = LoadQueueSong(file, line);
if (!playlist_check_translate_song(*song, nullptr, loader))
if (!playlist_check_translate_song(song, nullptr, loader))
return;
queue.Append(std::move(*song), priority);
queue.Append(std::move(song), priority);
}