3 ms·
All of the vector operations return new vectors instead of mutating. func v3_add (a, b v3) v3 { return v3{x: a.x + b.x, y: a.y + b.y, z: a.z + b.z}
by Lerc 8y ago
All of the vector operations return new vectors instead of mutating.
func v3_add (a, b v3) v3 {
return v3{x: a.x + b.x, y: a.y + b.y, z: a.z + b.z}
}
A sensible approach for maintainable code but without knowing if a and b are used elsewhere the compiler can't reuse the space they occupy. If C can't figure it out, it can just stick a new one on the stack which doesn't cost too much.
This is, of course, Rust's bread and butter which is probably why it takes the top spot.
- weberc2 8y agoThose are copied on the stack, not heap allocated, so the GC wouldn't come into play.