#Why do the `std.mem.Allocator` methods pass self by value?
1 messages · Page 1 of 1 (latest)
It's a vtable
has only pointers
already constant
and if zig can decide by itself if you need to pass it by reference
(Arguments in zig are inmutable)
So, zig will do optimizations like this on it's own?
yes
By the langref:
Structs, unions, and arrays can sometimes be more efficiently passed as a reference, since a copy could be arbitrarily expensive depending on the size. When these types are passed as parameters, Zig may choose to copy and pass by value, or pass by reference, whichever way Zig decides will be faster. This is made possible, in part, by the fact that parameters are immutable.