Skip to content

Commit d4c1b8b

Browse files
committed
fable: Use pass-by-value + move in Conf constructor
1 parent 8559fc1 commit d4c1b8b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

fable/include/fable/conf.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ class ConfError;
6868
class Conf {
6969
public:
7070
Conf() = default;
71-
explicit Conf(const Json& data) : data_(data) {}
72-
explicit Conf(const std::string& file);
73-
Conf(const Json& data, const std::string& file) : file_(file), data_(data) {}
74-
Conf(const Json& data, const std::string& file, const std::string& root)
75-
: file_(file), root_(root), data_(data) {}
71+
explicit Conf(Json data) : data_(std::move(data)) {}
72+
explicit Conf(std::string file);
73+
Conf(Json data, std::string file) : file_(std::move(file)), data_(std::move(data)) {}
74+
Conf(Json data, std::string file, std::string root)
75+
: file_(std::move(file)), root_(std::move(root)), data_(std::move(data)) {}
7676

7777
/**
7878
* Return whether this configuration was read from a file.

fable/src/fable/conf.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434

3535
namespace fable {
3636

37-
Conf::Conf(const std::string& file) : file_(file) {
37+
Conf::Conf(std::string file) : file_(std::move(file)) {
3838
std::ifstream ifs(file_);
3939
if (ifs.fail()) {
40-
throw Error("could not open file {}: {}", file, strerror(errno));
40+
throw Error("could not open file {}: {}", file_, strerror(errno));
4141
}
4242
try {
4343
data_ = parse_json(ifs);
4444
} catch (std::exception& e) {
45-
throw Error("unable to parse file {}: {}", file, e.what());
45+
throw Error("unable to parse file {}: {}", file_, e.what());
4646
}
4747
}
4848

0 commit comments

Comments
 (0)