util/UriExtract: uri_get_suffix() returns std::string_view

No need to copy it to a buffer.
This commit is contained in:
Max Kellermann
2020-11-04 20:39:06 +01:00
parent 19dd1a25d7
commit 35a232105e
14 changed files with 72 additions and 115 deletions

View File

@@ -72,12 +72,12 @@ protected:
private:
void DecodeStream(InputStream &is, const DecoderPlugin &plugin);
bool DecodeStream(InputStream &is, const char *suffix,
bool DecodeStream(InputStream &is, std::string_view suffix,
const DecoderPlugin &plugin);
void DecodeStream(InputStream &is);
bool DecodeContainer(const char *suffix, const DecoderPlugin &plugin);
bool DecodeContainer(const char *suffix);
bool DecodeFile(const char *suffix, InputStream &is,
bool DecodeContainer(std::string_view suffix, const DecoderPlugin &plugin);
bool DecodeContainer(std::string_view suffix);
bool DecodeFile(std::string_view suffix, InputStream &is,
const DecoderPlugin &plugin);
void DecodeFile();
@@ -130,17 +130,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) ||
@@ -149,7 +149,7 @@ decoder_check_plugin(const DecoderPlugin &plugin, const InputStream &is,
inline bool
GetChromaprintCommand::DecodeStream(InputStream &is,
const char *suffix,
std::string_view suffix,
const DecoderPlugin &plugin)
{
if (!decoder_check_plugin(plugin, is, suffix))
@@ -164,8 +164,7 @@ GetChromaprintCommand::DecodeStream(InputStream &is,
inline void
GetChromaprintCommand::DecodeStream(InputStream &is)
{
UriSuffixBuffer suffix_buffer;
const char *const suffix = uri_get_suffix(uri.c_str(), suffix_buffer);
const auto suffix = uri_get_suffix(uri.c_str());
decoder_plugins_try([this, &is, suffix](const DecoderPlugin &plugin){
return DecodeStream(is, suffix, plugin);
@@ -173,7 +172,7 @@ GetChromaprintCommand::DecodeStream(InputStream &is)
}
inline bool
GetChromaprintCommand::DecodeContainer(const char *suffix,
GetChromaprintCommand::DecodeContainer(std::string_view suffix,
const DecoderPlugin &plugin)
{
if (plugin.container_scan == nullptr ||
@@ -188,7 +187,7 @@ GetChromaprintCommand::DecodeContainer(const char *suffix,
}
inline bool
GetChromaprintCommand::DecodeContainer(const char *suffix)
GetChromaprintCommand::DecodeContainer(std::string_view suffix)
{
return decoder_plugins_try([this, suffix](const DecoderPlugin &plugin){
return DecodeContainer(suffix, plugin);
@@ -196,7 +195,7 @@ GetChromaprintCommand::DecodeContainer(const char *suffix)
}
inline bool
GetChromaprintCommand::DecodeFile(const char *suffix, InputStream &is,
GetChromaprintCommand::DecodeFile(std::string_view suffix, InputStream &is,
const DecoderPlugin &plugin)
{
if (!plugin.SupportsSuffix(suffix))
@@ -223,8 +222,8 @@ GetChromaprintCommand::DecodeFile(const char *suffix, InputStream &is,
inline void
GetChromaprintCommand::DecodeFile()
{
const char *suffix = uri_get_suffix(uri.c_str());
if (suffix == nullptr)
const auto suffix = uri_get_suffix(uri.c_str());
if (suffix.empty())
return;
InputStreamPtr input_stream;