summaryrefslogtreecommitdiff
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-06-06 12:02:55 +0200
committerMax Kellermann <max@musicpd.org>2019-06-06 13:00:53 +0200
commit548aa00111e781c6b31e9a2486306d607081b1ec (patch)
treef44be7fd991040473082f1b2431c06c8e4c7aeb4 /src/decoder
parent76eb550011312cf5c096c86e7920decfe139b63d (diff)
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.
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/plugins/AdPlugDecoderPlugin.cxx3
-rw-r--r--src/decoder/plugins/DsdiffDecoderPlugin.cxx6
-rw-r--r--src/decoder/plugins/FfmpegMetaData.cxx1
-rw-r--r--src/decoder/plugins/GmeDecoderPlugin.cxx5
-rw-r--r--src/decoder/plugins/MikmodDecoderPlugin.cxx1
-rw-r--r--src/decoder/plugins/ModplugDecoderPlugin.cxx1
-rw-r--r--src/decoder/plugins/SidplayDecoderPlugin.cxx5
-rw-r--r--src/decoder/plugins/SndfileDecoderPlugin.cxx1
8 files changed, 15 insertions, 8 deletions
diff --git a/src/decoder/plugins/AdPlugDecoderPlugin.cxx b/src/decoder/plugins/AdPlugDecoderPlugin.cxx
index c082f6f2f..ba1d9c013 100644
--- a/src/decoder/plugins/AdPlugDecoderPlugin.cxx
+++ b/src/decoder/plugins/AdPlugDecoderPlugin.cxx
@@ -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
diff --git a/src/decoder/plugins/DsdiffDecoderPlugin.cxx b/src/decoder/plugins/DsdiffDecoderPlugin.cxx
index 1e4d9799c..a46d678bf 100644
--- a/src/decoder/plugins/DsdiffDecoderPlugin.cxx
+++ b/src/decoder/plugins/DsdiffDecoderPlugin.cxx
@@ -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;
}
diff --git a/src/decoder/plugins/FfmpegMetaData.cxx b/src/decoder/plugins/FfmpegMetaData.cxx
index 265722f49..61b2a9245 100644
--- a/src/decoder/plugins/FfmpegMetaData.cxx
+++ b/src/decoder/plugins/FfmpegMetaData.cxx
@@ -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>
diff --git a/src/decoder/plugins/GmeDecoderPlugin.cxx b/src/decoder/plugins/GmeDecoderPlugin.cxx
index 64f0a1ad4..2b2ea38f3 100644
--- a/src/decoder/plugins/GmeDecoderPlugin.cxx
+++ b/src/decoder/plugins/GmeDecoderPlugin.cxx
@@ -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);
}
diff --git a/src/decoder/plugins/MikmodDecoderPlugin.cxx b/src/decoder/plugins/MikmodDecoderPlugin.cxx
index e023dd2c4..1a62dc501 100644
--- a/src/decoder/plugins/MikmodDecoderPlugin.cxx
+++ b/src/decoder/plugins/MikmodDecoderPlugin.cxx
@@ -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>
diff --git a/src/decoder/plugins/ModplugDecoderPlugin.cxx b/src/decoder/plugins/ModplugDecoderPlugin.cxx
index d3d91efe1..96696ad1d 100644
--- a/src/decoder/plugins/ModplugDecoderPlugin.cxx
+++ b/src/decoder/plugins/ModplugDecoderPlugin.cxx
@@ -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>
diff --git a/src/decoder/plugins/SidplayDecoderPlugin.cxx b/src/decoder/plugins/SidplayDecoderPlugin.cxx
index 3d34b4436..71e530e34 100644
--- a/src/decoder/plugins/SidplayDecoderPlugin.cxx
+++ b/src/decoder/plugins/SidplayDecoderPlugin.cxx
@@ -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
diff --git a/src/decoder/plugins/SndfileDecoderPlugin.cxx b/src/decoder/plugins/SndfileDecoderPlugin.cxx
index 08cbb88c1..315af0589 100644
--- a/src/decoder/plugins/SndfileDecoderPlugin.cxx
+++ b/src/decoder/plugins/SndfileDecoderPlugin.cxx
@@ -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>