SongSave: return DetachedSong, not a std::unique_ptr<>
Eliminate unnecessary dynamic allocations.
This commit is contained in:
parent
a1e2602c3d
commit
07f212c98c
@ -81,11 +81,11 @@ song_save(BufferedOutputStream &os, const DetachedSong &song)
|
|||||||
os.Format(SONG_END "\n");
|
os.Format(SONG_END "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<DetachedSong>
|
DetachedSong
|
||||||
song_load(TextFile &file, const char *uri,
|
song_load(TextFile &file, const char *uri,
|
||||||
AudioFormat *audio_format_r)
|
AudioFormat *audio_format_r)
|
||||||
{
|
{
|
||||||
auto song = std::make_unique<DetachedSong>(uri);
|
DetachedSong song(uri);
|
||||||
|
|
||||||
TagBuilder tag;
|
TagBuilder tag;
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ song_load(TextFile &file, const char *uri,
|
|||||||
} else if (StringIsEqual(line, "Playlist")) {
|
} else if (StringIsEqual(line, "Playlist")) {
|
||||||
tag.SetHasPlaylist(StringIsEqual(value, "yes"));
|
tag.SetHasPlaylist(StringIsEqual(value, "yes"));
|
||||||
} else if (StringIsEqual(line, SONG_MTIME)) {
|
} 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")) {
|
} else if (StringIsEqual(line, "Range")) {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
@ -126,13 +126,13 @@ song_load(TextFile &file, const char *uri,
|
|||||||
? strtoul(endptr + 1, nullptr, 10)
|
? strtoul(endptr + 1, nullptr, 10)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
song->SetStartTime(SongTime::FromMS(start_ms));
|
song.SetStartTime(SongTime::FromMS(start_ms));
|
||||||
song->SetEndTime(SongTime::FromMS(end_ms));
|
song.SetEndTime(SongTime::FromMS(end_ms));
|
||||||
} else {
|
} else {
|
||||||
throw FormatRuntimeError("unknown line in db: %s", line);
|
throw FormatRuntimeError("unknown line in db: %s", line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
song->SetTag(tag.Commit());
|
song.SetTag(tag.Commit());
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song);
|
|||||||
*
|
*
|
||||||
* Throws on error.
|
* Throws on error.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<DetachedSong>
|
DetachedSong
|
||||||
song_load(TextFile &file, const char *uri,
|
song_load(TextFile &file, const char *uri,
|
||||||
AudioFormat *audio_format_r=nullptr);
|
AudioFormat *audio_format_r=nullptr);
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ 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 = std::make_unique<Song>(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;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ queue_save(BufferedOutputStream &os, const Queue &queue)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<DetachedSong>
|
static DetachedSong
|
||||||
LoadQueueSong(TextFile &file, const char *line)
|
LoadQueueSong(TextFile &file, const char *line)
|
||||||
{
|
{
|
||||||
std::unique_ptr<DetachedSong> song;
|
std::unique_ptr<DetachedSong> song;
|
||||||
@ -89,7 +89,7 @@ LoadQueueSong(TextFile &file, const char *line)
|
|||||||
|
|
||||||
const char *uri = endptr + 1;
|
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);
|
auto song = LoadQueueSong(file, line);
|
||||||
|
|
||||||
if (!playlist_check_translate_song(*song, nullptr, loader))
|
if (!playlist_check_translate_song(song, nullptr, loader))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
queue.Append(std::move(*song), priority);
|
queue.Append(std::move(song), priority);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user