summaryrefslogtreecommitdiff
path: root/test
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 /test
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 'test')
-rw-r--r--test/read_tags.cxx12
1 files changed, 8 insertions, 4 deletions
diff --git a/test/read_tags.cxx b/test/read_tags.cxx
index a8ab2a061..78703e436 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -30,6 +30,7 @@
#include "AudioFormat.hxx"
#include "util/ScopeExit.hxx"
#include "util/StringBuffer.hxx"
+#include "util/StringView.hxx"
#include "util/PrintException.hxx"
#include <stdexcept>
@@ -58,13 +59,16 @@ public:
printf("duration=%f\n", duration.ToDoubleS());
}
- void OnTag(TagType type, const char *value) noexcept override {
- printf("[%s]=%s\n", tag_item_names[type], value);
+ void OnTag(TagType type, StringView value) noexcept override {
+ printf("[%s]=%.*s\n", tag_item_names[type],
+ int(value.size), value.data);
empty = false;
}
- void OnPair(const char *key, const char *value) noexcept override {
- printf("\"%s\"=%s\n", key, value);
+ void OnPair(StringView key, StringView value) noexcept override {
+ printf("\"%.*s\"=%.*s\n",
+ int(key.size), key.data,
+ int(value.size), value.data);
}
void OnAudioFormat(AudioFormat af) noexcept override {