mirror of
https://git.suyu.dev/suyu/sirit.git
synced 2026-03-11 05:42:57 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
LiteralString::LiteralString(const std::string& string) : string(string) {
|
||||
LiteralString::LiteralString(std::string string) : string{std::move(string)} {
|
||||
operand_type = OperandType::String;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Sirit {
|
||||
|
||||
class LiteralString : public Operand {
|
||||
public:
|
||||
LiteralString(const std::string& string);
|
||||
LiteralString(std::string string);
|
||||
~LiteralString() override;
|
||||
|
||||
void Fetch(Stream& stream) const override;
|
||||
|
||||
@@ -110,8 +110,8 @@ void Op::Add(u32 integer) {
|
||||
Sink(LiteralNumber::Create<u32>(integer));
|
||||
}
|
||||
|
||||
void Op::Add(const std::string& string) {
|
||||
Sink(new LiteralString(string));
|
||||
void Op::Add(std::string string) {
|
||||
Sink(new LiteralString(std::move(string)));
|
||||
}
|
||||
|
||||
void Op::Add(const std::vector<Id>& ids) {
|
||||
|
||||
2
src/op.h
2
src/op.h
@@ -38,7 +38,7 @@ public:
|
||||
|
||||
void Add(u32 integer);
|
||||
|
||||
void Add(const std::string& string);
|
||||
void Add(std::string string);
|
||||
|
||||
void Add(const std::vector<Id>& ids);
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ std::vector<u8> Module::Assemble() const {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void Module::AddExtension(const std::string& extension_name) {
|
||||
extensions.insert(extension_name);
|
||||
void Module::AddExtension(std::string extension_name) {
|
||||
extensions.insert(std::move(extension_name));
|
||||
}
|
||||
|
||||
void Module::AddCapability(spv::Capability capability) {
|
||||
@@ -80,11 +80,11 @@ void Module::SetMemoryModel(spv::AddressingModel addressing_model, spv::MemoryMo
|
||||
}
|
||||
|
||||
void Module::AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point,
|
||||
const std::string& name, const std::vector<Id>& interfaces) {
|
||||
std::string name, const std::vector<Id>& interfaces) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpEntryPoint)};
|
||||
op->Add(static_cast<u32>(execution_model));
|
||||
op->Add(entry_point);
|
||||
op->Add(name);
|
||||
op->Add(std::move(name));
|
||||
op->Add(interfaces);
|
||||
entry_points.push_back(std::move(op));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user