util/UriExtract: uri_get_scheme() returns StringView

Reduce overhead by not duplicating the string.
This commit is contained in:
Max Kellermann 2019-08-09 16:09:40 +02:00
parent 40a2880857
commit 9c6850210d
3 changed files with 6 additions and 6 deletions

View File

@ -123,7 +123,7 @@ playlist_list_open_uri_scheme(const char *uri, Mutex &mutex,
if (playlist_plugins_enabled[i] && plugin->open_uri != nullptr && if (playlist_plugins_enabled[i] && plugin->open_uri != nullptr &&
plugin->schemes != nullptr && plugin->schemes != nullptr &&
StringArrayContainsCase(plugin->schemes, scheme.c_str())) { StringArrayContainsCase(plugin->schemes, scheme)) {
auto playlist = plugin->open_uri(uri, mutex); auto playlist = plugin->open_uri(uri, mutex);
if (playlist) if (playlist)
return playlist; return playlist;

View File

@ -85,14 +85,14 @@ uri_has_scheme(const char *uri) noexcept
return strstr(uri, "://") != nullptr; return strstr(uri, "://") != nullptr;
} }
std::string StringView
uri_get_scheme(const char *uri) noexcept uri_get_scheme(const char *uri) noexcept
{ {
const char *end = strstr(uri, "://"); const char *end = strstr(uri, "://");
if (end == nullptr) if (end == nullptr)
end = uri; return nullptr;
return std::string(uri, end); return {uri, end};
} }
const char * const char *

View File

@ -32,7 +32,7 @@
#include "Compiler.h" #include "Compiler.h"
#include <string> struct StringView;
/** /**
* Checks whether the specified URI has a scheme in the form * Checks whether the specified URI has a scheme in the form
@ -46,7 +46,7 @@ uri_has_scheme(const char *uri) noexcept;
* Returns the scheme name of the specified URI, or an empty string. * Returns the scheme name of the specified URI, or an empty string.
*/ */
gcc_pure gcc_pure
std::string StringView
uri_get_scheme(const char *uri) noexcept; uri_get_scheme(const char *uri) noexcept;
/** /**