tag/Handler: pass StringView to OnTag() and OnPair()

Eliminates a number of allocations, because callers don't need to copy
the strings to a newly allocated buffer only to null-terminate them.
And most callers don't need to have a null-terminated string.
This commit is contained in:
Max Kellermann
2019-06-06 12:02:55 +02:00
parent 76eb550011
commit 548aa00111
19 changed files with 108 additions and 62 deletions

View File

@@ -29,6 +29,7 @@
#include "fs/FileSystem.hxx"
#include "util/ScopeExit.hxx"
#include "util/StringFormat.hxx"
#include "util/StringView.hxx"
#include "util/UriUtil.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
@@ -220,7 +221,7 @@ ScanGmeInfo(const gme_info_t &info, unsigned song_num, int track_count,
handler.OnDuration(SongTime::FromMS(info.play_length));
if (track_count > 1)
handler.OnTag(TAG_TRACK, StringFormat<16>("%u", song_num + 1));
handler.OnTag(TAG_TRACK, StringFormat<16>("%u", song_num + 1).c_str());
if (info.song != nullptr) {
if (track_count > 1) {
@@ -229,7 +230,7 @@ ScanGmeInfo(const gme_info_t &info, unsigned song_num, int track_count,
StringFormat<1024>("%s (%u/%d)",
info.song, song_num + 1,
track_count);
handler.OnTag(TAG_TITLE, tag_title);
handler.OnTag(TAG_TITLE, tag_title.c_str());
} else
handler.OnTag(TAG_TITLE, info.song);
}