It depends on how you will use vec
. If you're not having a lot of entries in the vector it's okay to pass it by value as the copying will be pretty quick. But generally it's more "effective" to pass it by reference.
The val
argument on the other hand, for native types there is generally no need to pass them as constant references. Actually, as references are often (if not always?) implemented as pointers under the hood, passing this parameter as a reference will on a 64-bit machine pass a 64-bit value compared to a 32-bit value for plain int
. And as this is a pointer, it will use extra indirection as well.