summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-08-09 16:09:40 +0200
committerMax Kellermann <max@musicpd.org>2019-08-09 20:21:37 +0200
commit9c6850210df7157e6b7d7c7b92fc14f08a29263c (patch)
treeda4f8365ceeef3e86a92388109e76e67a24effd9 /src
parent40a288085769e83354d619500721911561b16f26 (diff)
util/UriExtract: uri_get_scheme() returns StringView
Reduce overhead by not duplicating the string.
Diffstat (limited to 'src')
-rw-r--r--src/playlist/PlaylistRegistry.cxx2
-rw-r--r--src/util/UriExtract.cxx6
-rw-r--r--src/util/UriExtract.hxx4
3 files changed, 6 insertions, 6 deletions
diff --git a/src/playlist/PlaylistRegistry.cxx b/src/playlist/PlaylistRegistry.cxx
index 0571cd904..7c87b4443 100644
--- a/src/playlist/PlaylistRegistry.cxx
+++ b/src/playlist/PlaylistRegistry.cxx
@@ -123,7 +123,7 @@ playlist_list_open_uri_scheme(const char *uri, Mutex &mutex,
if (playlist_plugins_enabled[i] && plugin->open_uri != nullptr &&
plugin->schemes != nullptr &&
- StringArrayContainsCase(plugin->schemes, scheme.c_str())) {
+ StringArrayContainsCase(plugin->schemes, scheme)) {
auto playlist = plugin->open_uri(uri, mutex);
if (playlist)
return playlist;
diff --git a/src/util/UriExtract.cxx b/src/util/UriExtract.cxx
index ac9eba628..72ac284d9 100644
--- a/src/util/UriExtract.cxx
+++ b/src/util/UriExtract.cxx
@@ -85,14 +85,14 @@ uri_has_scheme(const char *uri) noexcept
return strstr(uri, "://") != nullptr;
}
-std::string
+StringView
uri_get_scheme(const char *uri) noexcept
{
const char *end = strstr(uri, "://");
if (end == nullptr)
- end = uri;
+ return nullptr;
- return std::string(uri, end);
+ return {uri, end};
}
const char *
diff --git a/src/util/UriExtract.hxx b/src/util/UriExtract.hxx
index 46af8ae1e..23ed2c12a 100644
--- a/src/util/UriExtract.hxx
+++ b/src/util/UriExtract.hxx
@@ -32,7 +32,7 @@
#include "Compiler.h"
-#include <string>
+struct StringView;
/**
* 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.
*/
gcc_pure
-std::string
+StringView
uri_get_scheme(const char *uri) noexcept;
/**