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

@@ -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;
}