config/Data: pass new items by rvalue reference

This commit is contained in:
Max Kellermann 2018-07-18 11:21:59 +02:00
parent 9ff2606bb8
commit 57729683b6
3 changed files with 13 additions and 17 deletions

View File

@ -56,9 +56,9 @@ Append(std::forward_list<T> &list, T &&src)
void
ConfigData::AddParam(ConfigOption option,
std::unique_ptr<ConfigParam> param) noexcept
ConfigParam &&param) noexcept
{
Append(GetParamList(option), std::move(*param));
Append(GetParamList(option), std::move(param));
}
const char *
@ -144,9 +144,9 @@ ConfigData::GetBool(ConfigOption option, bool default_value) const
ConfigBlock &
ConfigData::AddBlock(ConfigBlockOption option,
std::unique_ptr<ConfigBlock> block) noexcept
ConfigBlock &&block) noexcept
{
return *Append(GetBlockList(option), std::move(*block));
return *Append(GetBlockList(option), std::move(block));
}
const ConfigBlock *
@ -172,8 +172,8 @@ ConfigData::MakeBlock(ConfigBlockOption option,
{
auto *block = const_cast<ConfigBlock *>(FindBlock(option, key, value));
if (block == nullptr) {
auto new_block = std::make_unique<ConfigBlock>();
new_block->AddBlockParam(key, value);
ConfigBlock new_block;
new_block.AddBlockParam(key, value);
block = &AddBlock(option, std::move(new_block));
}

View File

@ -27,7 +27,6 @@
#include <array>
#include <chrono>
#include <forward_list>
#include <memory>
struct ConfigParam;
struct ConfigBlock;
@ -47,8 +46,7 @@ struct ConfigData {
return params[size_t(option)];
}
void AddParam(ConfigOption option,
std::unique_ptr<ConfigParam> param) noexcept;
void AddParam(ConfigOption option, ConfigParam &&param) noexcept;
gcc_pure
const ConfigParam *GetParam(ConfigOption option) const noexcept {
@ -102,7 +100,7 @@ struct ConfigData {
}
ConfigBlock &AddBlock(ConfigBlockOption option,
std::unique_ptr<ConfigBlock> block) noexcept;
ConfigBlock &&block) noexcept;
gcc_pure
const ConfigBlock *GetBlock(ConfigBlockOption option) const noexcept {

View File

@ -32,8 +32,6 @@
#include "fs/io/BufferedReader.hxx"
#include "Log.hxx"
#include <memory>
#include <assert.h>
static constexpr char CONF_COMMENT = '#';
@ -74,10 +72,10 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line)
block.AddBlockParam(name, std::move(value), line);
}
static std::unique_ptr<ConfigBlock>
static ConfigBlock
config_read_block(BufferedReader &reader)
{
std::unique_ptr<ConfigBlock> block(new ConfigBlock(reader.GetLineNumber()));
ConfigBlock block(reader.GetLineNumber());
while (true) {
char *line = reader.ReadLine();
@ -101,7 +99,7 @@ config_read_block(BufferedReader &reader)
/* parse name and value */
config_read_name_value(*block, line,
config_read_name_value(block, line,
reader.GetLineNumber());
}
}
@ -150,8 +148,8 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader,
/* now parse the block or the value */
config_data.AddParam(o, std::make_unique<ConfigParam>(ExpectValueAndEnd(tokenizer),
reader.GetLineNumber()));
config_data.AddParam(o, ConfigParam(ExpectValueAndEnd(tokenizer),
reader.GetLineNumber()));
}
static void