Skip to content

[Question] When to pass copy vs ref? #422

Answered by bitshifter
Indra-db asked this question in Q&A
Discussion options

You must be logged in to vote

There's not really a hard and fast rule and I don't remember the rules of the Rust ABI. Most of glam is inlined, so it shouldn't make too much difference which one is used. Usually I look at the generated assembly and maybe write a benchmark with both styles to see what seems best. Most likely in an optimised build they will be the same, there might be differences in debug builds which can be a consideration In glam I mostly only use &self with large structures like 4x4 matrices and even then, I don't recall if the asm was different, I made those decisions a while ago :)

Here's an example in godbolt, with one implementation of cross taking self and the other taking &self, the generated co…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Indra-db
Comment options

Answer selected by Indra-db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants