From af3f637d3f91be1bc85c98444effd1ebae8d4d2b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 3 Sep 2019 20:25:04 +0200 Subject: [PATCH] db/simple/Song: pass StringView to constructor --- src/db/plugins/simple/Song.cxx | 17 ++++++----------- src/db/plugins/simple/Song.hxx | 3 ++- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/db/plugins/simple/Song.cxx b/src/db/plugins/simple/Song.cxx index b43ab60f7..0ff9cda07 100644 --- a/src/db/plugins/simple/Song.cxx +++ b/src/db/plugins/simple/Song.cxx @@ -24,15 +24,16 @@ #include "util/VarSize.hxx" #include "song/DetachedSong.hxx" #include "song/LightSong.hxx" +#include "util/StringView.hxx" #include #include inline -Song::Song(const char *_uri, size_t uri_length, Directory &_parent) noexcept +Song::Song(StringView _uri, Directory &_parent) noexcept :parent(&_parent) { - memcpy(uri, _uri, uri_length + 1); + memcpy(uri, _uri.data, _uri.size + 1); } inline @@ -41,17 +42,11 @@ Song::~Song() noexcept } static SongPtr -song_alloc(const char *uri, Directory &parent) noexcept +song_alloc(StringView uri, Directory &parent) noexcept { - size_t uri_length; - - assert(uri); - uri_length = strlen(uri); - assert(uri_length); - auto *song = NewVarSize(sizeof(Song::uri), - uri_length + 1, - uri, uri_length, parent); + uri.size + 1, + uri, parent); return SongPtr(song); } diff --git a/src/db/plugins/simple/Song.hxx b/src/db/plugins/simple/Song.hxx index b37feef01..aa034e02d 100644 --- a/src/db/plugins/simple/Song.hxx +++ b/src/db/plugins/simple/Song.hxx @@ -31,6 +31,7 @@ #include +struct StringView; struct LightSong; struct Directory; class DetachedSong; @@ -93,7 +94,7 @@ struct Song { */ char uri[sizeof(int)]; - Song(const char *_uri, size_t uri_length, Directory &parent) noexcept; + Song(StringView _uri, Directory &parent) noexcept; ~Song() noexcept; static SongPtr NewFrom(DetachedSong &&other, Directory &parent) noexcept;