Pass std::string by value where applicable.

By taking the std::string by value in the constructor, this allows for
certain situations where copies can be elided entirely (when moving an
instance into the constructor)

e.g.

std::string var = ...

...

... = LiteralString(std::move(var)) // Or whatever other initialization
                                    // is done.

No copy will be done in this case, the move transfers it into the
constructor, and then the move within the initializer list transfers it
into the member variable.

tl;dr: This allows the calling code to potentially construct less
std::string instances by allowing moving into the parameters themselves.
This commit is contained in:
Lioncash 2019-03-14 02:52:54 -04:00 committed by ReinUsesLisp
parent d5c37d242a
commit 6fd44e494c
8 changed files with 27 additions and 27 deletions

View file

@ -11,26 +11,26 @@
namespace Sirit {
Id Module::Name(Id target, const std::string& name) {
Id Module::Name(Id target, std::string name) {
auto op{std::make_unique<Op>(spv::Op::OpName)};
op->Add(target);
op->Add(name);
op->Add(std::move(name));
debug.push_back(std::move(op));
return target;
}
Id Module::MemberName(Id type, u32 member, const std::string& name) {
Id Module::MemberName(Id type, u32 member, std::string name) {
auto op{std::make_unique<Op>(spv::Op::OpMemberName)};
op->Add(type);
op->Add(member);
op->Add(name);
op->Add(std::move(name));
debug.push_back(std::move(op));
return type;
}
Id Module::String(const std::string& string) {
Id Module::String(std::string string) {
auto op{std::make_unique<Op>(spv::Op::OpString, bound++)};
op->Add(string);
op->Add(std::move(string));
const auto id = op.get();
debug.push_back(std::move(op));
return id;

View file

@ -96,9 +96,9 @@ Id Module::TypeStruct(const std::vector<Id>& members) {
return AddDeclaration(std::move(op));
}
Id Module::TypeOpaque(const std::string& name) {
Id Module::TypeOpaque(std::string name) {
auto op{std::make_unique<Op>(spv::Op::OpTypeOpaque, bound)};
op->Add(name);
op->Add(std::move(name));
return AddDeclaration(std::move(op));
}