Skip to content

Commit 715ef84

Browse files
committed
input/Plugin: pass URI as std::string_view
1 parent aee49d1 commit 715ef84

35 files changed

+85
-92
lines changed

src/RemoteTagCache.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ RemoteTagCache::Lookup(const std::string &uri) noexcept
3636
lock.unlock();
3737

3838
try {
39-
item->scanner = InputScanTags(uri.c_str(), *item);
39+
item->scanner = InputScanTags(uri, *item);
4040
if (!item->scanner) {
4141
/* unsupported */
4242
lock.lock();

src/command/FileCommands.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ find_stream_art(std::string_view directory, Mutex &mutex)
146146
std::string art_file = PathTraitsUTF8::Build(directory, name);
147147

148148
try {
149-
return InputStream::OpenReady(art_file.c_str(), mutex);
149+
return InputStream::OpenReady(art_file, mutex);
150150
} catch (...) {
151151
auto e = std::current_exception();
152152
if (!IsFileNotFound(e))

src/command/FingerprintCommands.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class GetChromaprintCommand final
6868
void DecodeFile();
6969

7070
/* virtual methods from class DecoderClient */
71-
InputStreamPtr OpenUri(const char *uri) override;
71+
InputStreamPtr OpenUri(std::string_view uri) override;
7272
size_t Read(InputStream &is,
7373
std::span<std::byte> dest) noexcept override;
7474

@@ -246,14 +246,14 @@ try {
246246
if (!path.IsNull())
247247
DecodeFile();
248248
else
249-
DecodeStream(*OpenUri(uri.c_str()));
249+
DecodeStream(*OpenUri(uri));
250250

251251
ChromaprintDecoderClient::Finish();
252252
} catch (StopDecoder) {
253253
}
254254

255255
InputStreamPtr
256-
GetChromaprintCommand::OpenUri(const char *uri2)
256+
GetChromaprintCommand::OpenUri(std::string_view uri2)
257257
{
258258
if (cancel)
259259
throw StopDecoder();

src/decoder/Bridge.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ DecoderBridge::SeekError() noexcept
372372
}
373373

374374
InputStreamPtr
375-
DecoderBridge::OpenUri(const char *uri)
375+
DecoderBridge::OpenUri(std::string_view uri)
376376
{
377377
assert(dc.state == DecoderState::START ||
378378
dc.state == DecoderState::DECODE);

src/decoder/Bridge.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public:
158158
SongTime GetSeekTime() noexcept override;
159159
uint64_t GetSeekFrame() noexcept override;
160160
void SeekError() noexcept override;
161-
InputStreamPtr OpenUri(const char *uri) override;
161+
InputStreamPtr OpenUri(std::string_view uri) override;
162162
size_t Read(InputStream &is,
163163
std::span<std::byte> dest) noexcept override;
164164
void SubmitTimestamp(FloatDuration t) noexcept override;

src/decoder/Client.hxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cstddef>
1111
#include <cstdint>
1212
#include <span>
13+
#include <string_view>
1314

1415
struct AudioFormat;
1516
struct Tag;
@@ -80,7 +81,7 @@ public:
8081
*
8182
* Throws std::runtime_error on error.
8283
*/
83-
virtual InputStreamPtr OpenUri(const char *uri) = 0;
84+
virtual InputStreamPtr OpenUri(std::string_view uri) = 0;
8485

8586
/**
8687
* Blocking read from the input stream.

src/decoder/Thread.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ decoder_run_stream_plugin(DecoderBridge &bridge, InputStream &is,
227227
static DecodeResult
228228
decoder_run_stream_locked(DecoderBridge &bridge, InputStream &is,
229229
std::unique_lock<Mutex> &lock,
230-
const char *uri)
230+
std::string_view uri)
231231
{
232232
const auto suffix = uri_get_suffix(uri);
233233

src/decoder/plugins/WavpackDecoderPlugin.cxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "fs/Path.hxx"
1212
#include "lib/fmt/PathFormatter.hxx"
1313
#include "lib/fmt/RuntimeError.hxx"
14-
#include "util/AllocatedString.hxx"
1514
#include "util/Math.hxx"
1615
#include "util/ScopeExit.hxx"
1716

@@ -407,10 +406,8 @@ static constexpr WavpackStreamReader64 mpd_is_reader = {
407406
static InputStreamPtr
408407
wavpack_open_wvc(DecoderClient &client, std::string_view uri)
409408
{
410-
const AllocatedString wvc_url{uri, "c"sv};
411-
412409
try {
413-
return client.OpenUri(wvc_url.c_str());
410+
return client.OpenUri(fmt::format("{}c", uri));
414411
} catch (...) {
415412
return nullptr;
416413
}

src/input/InputPlugin.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <iterator>
1010

1111
bool
12-
InputPlugin::SupportsUri(const char *uri) const noexcept
12+
InputPlugin::SupportsUri(std::string_view uri) const noexcept
1313
{
1414
assert(prefixes || protocols);
1515
if (prefixes != nullptr) {

src/input/InputPlugin.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct InputPlugin {
4747
*
4848
* Throws std::runtime_error on error.
4949
*/
50-
InputStreamPtr (*open)(const char *uri, Mutex &mutex);
50+
InputStreamPtr (*open)(std::string_view uri, Mutex &mutex);
5151

5252
/**
5353
* return a set of supported protocols
@@ -63,11 +63,11 @@ struct InputPlugin {
6363
*
6464
* @return nullptr if the given URI is not supported.
6565
*/
66-
std::unique_ptr<RemoteTagScanner> (*scan_tags)(const char *uri,
66+
std::unique_ptr<RemoteTagScanner> (*scan_tags)(std::string_view uri,
6767
RemoteTagHandler &handler) = nullptr;
6868

6969
[[gnu::pure]]
70-
bool SupportsUri(const char *uri) const noexcept;
70+
bool SupportsUri(std::string_view uri) const noexcept;
7171

7272
template<typename F>
7373
void ForeachSupportedUri(F lambda) const noexcept {

0 commit comments

Comments
 (0)