Commit 9c685021 authored by Max Kellermann's avatar Max Kellermann

util/UriExtract: uri_get_scheme() returns StringView

Reduce overhead by not duplicating the string.
parent 40a28808
...@@ -123,7 +123,7 @@ playlist_list_open_uri_scheme(const char *uri, Mutex &mutex, ...@@ -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;
......
...@@ -85,14 +85,14 @@ uri_has_scheme(const char *uri) noexcept ...@@ -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 *
......
...@@ -32,7 +32,7 @@ ...@@ -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; ...@@ -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;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment