From 7de6e4dbac02b3849c6e6ada7c006414989733e9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 11 Jun 2019 19:32:45 +0200 Subject: [PATCH] playlist/Registry: eliminate MIME type copy --- src/playlist/PlaylistRegistry.cxx | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/playlist/PlaylistRegistry.cxx b/src/playlist/PlaylistRegistry.cxx index b11012e9c..efcc77e17 100644 --- a/src/playlist/PlaylistRegistry.cxx +++ b/src/playlist/PlaylistRegistry.cxx @@ -201,22 +201,29 @@ playlist_list_open_stream_mime2(InputStreamPtr &&is, StringView mime) return nullptr; } +/** + * Extract the "main" part of a MIME type string, i.e. the portion + * before the semicolon (if one exists). + */ +gcc_pure +static StringView +ExtractMimeTypeMainPart(StringView s) noexcept +{ + const auto separator = s.Find(';'); + if (separator != nullptr) + s.SetEnd(separator); + + return s; +} + static std::unique_ptr playlist_list_open_stream_mime(InputStreamPtr &&is, const char *full_mime) { assert(full_mime != nullptr); - const char *semicolon = strchr(full_mime, ';'); - if (semicolon == nullptr) - return playlist_list_open_stream_mime2(std::move(is), - full_mime); - - if (semicolon == full_mime) - return nullptr; - /* probe only the portion before the semicolon*/ - const std::string mime(full_mime, semicolon); - return playlist_list_open_stream_mime2(std::move(is), mime.c_str()); + return playlist_list_open_stream_mime2(std::move(is), + ExtractMimeTypeMainPart(full_mime)); } std::unique_ptr