diff options
author | Max Kellermann <max@musicpd.org> | 2020-11-04 20:39:06 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-11-04 21:08:26 +0100 |
commit | 35a232105ee9b52e08dc41587d165f424e00cd5e (patch) | |
tree | e5a8a343be0f84976c8f69467e5ebbc8bec2f04a /src/decoder | |
parent | 19dd1a25d766243bfa3e373273ded7f818f4c9e7 (diff) |
util/UriExtract: uri_get_suffix() returns std::string_view
No need to copy it to a buffer.
Diffstat (limited to 'src/decoder')
-rw-r--r-- | src/decoder/Thread.cxx | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/decoder/Thread.cxx b/src/decoder/Thread.cxx index 00113063d..ee948a40f 100644 --- a/src/decoder/Thread.cxx +++ b/src/decoder/Thread.cxx @@ -178,17 +178,17 @@ decoder_check_plugin_mime(const DecoderPlugin &plugin, gcc_pure static bool decoder_check_plugin_suffix(const DecoderPlugin &plugin, - const char *suffix) noexcept + std::string_view suffix) noexcept { assert(plugin.stream_decode != nullptr); - return suffix != nullptr && plugin.SupportsSuffix(suffix); + return !suffix.empty() && plugin.SupportsSuffix(suffix); } gcc_pure static bool decoder_check_plugin(const DecoderPlugin &plugin, const InputStream &is, - const char *suffix) noexcept + std::string_view suffix) noexcept { return plugin.stream_decode != nullptr && (decoder_check_plugin_mime(plugin, is) || @@ -198,7 +198,7 @@ decoder_check_plugin(const DecoderPlugin &plugin, const InputStream &is, static bool decoder_run_stream_plugin(DecoderBridge &bridge, InputStream &is, std::unique_lock<Mutex> &lock, - const char *suffix, + std::string_view suffix, const DecoderPlugin &plugin, bool &tried_r) { @@ -216,8 +216,7 @@ decoder_run_stream_locked(DecoderBridge &bridge, InputStream &is, std::unique_lock<Mutex> &lock, const char *uri, bool &tried_r) { - UriSuffixBuffer suffix_buffer; - const char *const suffix = uri_get_suffix(uri, suffix_buffer); + const auto suffix = uri_get_suffix(uri); const auto f = [&,suffix](const auto &plugin) { return decoder_run_stream_plugin(bridge, is, lock, suffix, plugin, tried_r); }; @@ -326,7 +325,7 @@ decoder_run_stream(DecoderBridge &bridge, const char *uri) * DecoderControl::mutex is not locked by caller. */ static bool -TryDecoderFile(DecoderBridge &bridge, Path path_fs, const char *suffix, +TryDecoderFile(DecoderBridge &bridge, Path path_fs, std::string_view suffix, InputStream &input_stream, const DecoderPlugin &plugin) { @@ -354,7 +353,8 @@ TryDecoderFile(DecoderBridge &bridge, Path path_fs, const char *suffix, * DecoderControl::mutex is not locked by caller. */ static bool -TryContainerDecoder(DecoderBridge &bridge, Path path_fs, const char *suffix, +TryContainerDecoder(DecoderBridge &bridge, Path path_fs, + std::string_view suffix, const DecoderPlugin &plugin) { if (plugin.container_scan == nullptr || @@ -375,7 +375,8 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs, const char *suffix, * DecoderControl::mutex is not locked by caller. */ static bool -TryContainerDecoder(DecoderBridge &bridge, Path path_fs, const char *suffix) +TryContainerDecoder(DecoderBridge &bridge, Path path_fs, + std::string_view suffix) { return decoder_plugins_try([&bridge, path_fs, suffix](const DecoderPlugin &plugin){ @@ -394,8 +395,8 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs, const char *suffix) static bool decoder_run_file(DecoderBridge &bridge, const char *uri_utf8, Path path_fs) { - const char *suffix = uri_get_suffix(uri_utf8); - if (suffix == nullptr) + const auto suffix = uri_get_suffix(uri_utf8); + if (suffix.empty()) return false; InputStreamPtr input_stream; |