Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc] Use move semantics where possible #148

Merged
merged 3 commits into from
Jan 15, 2025

Conversation

st0rmbtw
Copy link
Contributor

No description provided.

const Format format,
std::uint32_t location = 0,
const SystemValue systemValue = SystemValue::Undefined)
StringLiteral name,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the performance benefits here? The constructor's parameter will now invoke a copy constructor, will it not? So the copy constructor of StringLiteral is either invoked at the caller side or at the callee side.

StringLiteral is also very lightweight, as long as the internal string was not dynamically allocated, e.g. when you use StringLiteral s = std::string("A") + "B" instead of the lightweight version StringLiteral s = "AB".

Copy link
Contributor Author

@st0rmbtw st0rmbtw Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor's parameter will now invoke a copy constructor, will it not?

It will copy if an lvalue is passed. If an rvalue is passed it will move it into the name local variable of the constructor and then move it again into the name variable of the struct.

I know it looks confusing, but it is what it is. There is an explanation for that on stackoverflow.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, that's indeed a great improvement. I've been stuck to the pass-by-reference-to-const method for the longest time. I also found another great article explaining this scenario: https://xania.org/202101/cpp-by-value-args
Would you mind also adding <utility> to the include directives in FragmentAttribute.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind also adding <utility> to the include directives in FragmentAttribute.h?

Yes, sure.

sources/Renderer/VertexAttribute.cpp Show resolved Hide resolved
semanticIndex { semanticIndex },
instanceDivisor { instanceDivisor }
name { std::move(semanticName) },
format { format },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate you following the same formatting style ❤️ I know it may seem a bit nitpicky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem :)

@LukasBanana LukasBanana self-assigned this Jan 15, 2025
@LukasBanana LukasBanana added the improvement General improvements and logical fixes. label Jan 15, 2025
@LukasBanana LukasBanana merged commit 5a70360 into LukasBanana:master Jan 15, 2025
46 of 47 checks passed
@LukasBanana
Copy link
Owner

Thanks for your contribution. The last build check only failed because I closed the PR before it could finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement General improvements and logical fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants