diff --git a/src/config/Block.hxx b/src/config/Block.hxx index 95157b694..01a41febf 100644 --- a/src/config/Block.hxx +++ b/src/config/Block.hxx @@ -40,9 +40,11 @@ struct BlockParam { */ mutable bool used = false; + template gcc_nonnull_all - BlockParam(const char *_name, const char *_value, int _line=-1) - :name(_name), value(_value), line(_line) {} + BlockParam(N &&_name, V &&_value, int _line=-1) noexcept + :name(std::forward(_name)), value(std::forward(_value)), + line(_line) {} int GetIntValue() const; @@ -92,10 +94,12 @@ struct ConfigBlock { return block_params.empty(); } + template gcc_nonnull_all - void AddBlockParam(const char *_name, const char *_value, - int _line=-1) { - block_params.emplace_back(_name, _value, _line); + void AddBlockParam(N &&_name, V &&_value, int _line=-1) noexcept { + block_params.emplace_back(std::forward(_name), + std::forward(_value), + _line); } gcc_nonnull_all gcc_pure diff --git a/src/db/Configured.cxx b/src/db/Configured.cxx index fc0c7d5dd..3c3eb8632 100644 --- a/src/db/Configured.cxx +++ b/src/db/Configured.cxx @@ -43,7 +43,7 @@ CreateConfiguredDatabase(EventLoop &main_event_loop, EventLoop &io_event_loop, listener, *param); else if (path != nullptr) { ConfigBlock block(path->line); - block.AddBlockParam("path", path->value.c_str(), path->line); + block.AddBlockParam("path", path->value, path->line); return DatabaseGlobalInit(main_event_loop, io_event_loop, listener, block); } else { @@ -54,12 +54,12 @@ CreateConfiguredDatabase(EventLoop &main_event_loop, EventLoop &io_event_loop, return nullptr; const auto db_file = cache_dir / Path::FromFS(PATH_LITERAL("mpd.db")); - const auto db_file_utf8 = db_file.ToUTF8(); + auto db_file_utf8 = db_file.ToUTF8(); if (db_file_utf8.empty()) return nullptr; ConfigBlock block; - block.AddBlockParam("path", db_file_utf8.c_str(), -1); + block.AddBlockParam("path", std::move(db_file_utf8), -1); return DatabaseGlobalInit(main_event_loop, io_event_loop, listener, block); } diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx index 43e45e184..aa04304b5 100644 --- a/test/DumpDatabase.cxx +++ b/test/DumpDatabase.cxx @@ -135,7 +135,7 @@ try { const auto *path = config_get_param(ConfigOption::DB_FILE); ConfigBlock block(path != nullptr ? path->line : -1); if (path != nullptr) - block.AddBlockParam("path", path->value.c_str(), path->line); + block.AddBlockParam("path", path->value, path->line); Database *db = plugin->create(init.GetEventLoop(), init.GetEventLoop(),