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:
@@ -24,6 +24,7 @@
|
||||
#include "fs/Path.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "util/Macros.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <adplug/adplug.h>
|
||||
@@ -85,7 +86,7 @@ adplug_scan_tag(TagType type, const std::string &value,
|
||||
TagHandler &handler) noexcept
|
||||
{
|
||||
if (!value.empty())
|
||||
handler.OnTag(type, value.c_str());
|
||||
handler.OnTag(type, {value.data(), value.size()});
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include "CheckAudioFormat.hxx"
|
||||
#include "util/bit_reverse.h"
|
||||
#include "util/ByteOrder.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "tag/Handler.hxx"
|
||||
#include "DsdLib.hxx"
|
||||
#include "Log.hxx"
|
||||
@@ -205,15 +206,14 @@ dsdiff_handle_native_tag(DecoderClient *client, InputStream &is,
|
||||
if (length == 0 || length > MAX_LENGTH)
|
||||
return;
|
||||
|
||||
char string[MAX_LENGTH + 1];
|
||||
char string[MAX_LENGTH];
|
||||
char *label;
|
||||
label = string;
|
||||
|
||||
if (!decoder_read_full(client, is, label, (size_t)length))
|
||||
return;
|
||||
|
||||
string[length] = '\0';
|
||||
handler.OnTag(type, label);
|
||||
handler.OnTag(type, {label, length});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "tag/Table.hxx"
|
||||
#include "tag/Handler.hxx"
|
||||
#include "tag/Id3MusicBrainz.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/dict.h>
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "fs/Path.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <mikmod.h>
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "util/WritableBuffer.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <libmodplug/modplug.h>
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#endif
|
||||
#include "util/Macros.hxx"
|
||||
#include "util/StringFormat.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "util/ByteOrder.hxx"
|
||||
#include "Log.hxx"
|
||||
@@ -460,7 +461,7 @@ ScanSidTuneInfo(const SidTuneInfo &info, unsigned track, unsigned n_tracks,
|
||||
const auto tag_title =
|
||||
StringFormat<1024>("%s (%u/%u)",
|
||||
title, track, n_tracks);
|
||||
handler.OnTag(TAG_TITLE, tag_title);
|
||||
handler.OnTag(TAG_TITLE, tag_title.c_str());
|
||||
} else
|
||||
handler.OnTag(TAG_TITLE, title);
|
||||
|
||||
@@ -475,7 +476,7 @@ ScanSidTuneInfo(const SidTuneInfo &info, unsigned track, unsigned n_tracks,
|
||||
handler.OnTag(TAG_DATE, date);
|
||||
|
||||
/* track */
|
||||
handler.OnTag(TAG_TRACK, StringFormat<16>("%u", track));
|
||||
handler.OnTag(TAG_TRACK, StringFormat<16>("%u", track).c_str());
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "tag/Handler.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "util/ScopeExit.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <exception>
|
||||
|
Reference in New Issue
Block a user