On 09/11/13 10:06, Igor Bukanov wrote:
On 8 November 2013 23:10, Oren Ben-Kiki <[email protected]> wrote:
Yes, the down side is another level of indirection. This could be optimized
away for &'static str, but not for &str. Good point.
The level of indirection comes from passing strings as &str, not just
as a plain str. But this raises the question. For immutable values
implementing &T parameter as T should not be observable from the safe
code, right? If so why not to declare that &T as a parameter is not a
pointer but rather a hint to use the fastest way to pass an instance
of T to the function. Then one can use &str as a parameter without any
performance impact due to indirection even if str itself is
fixed-sized 3-word block pointing to the heap allocated data.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

`&T` is pointer-sized but `T` isn't always.

(I believe that LLVM will optimise references to pass-by-value in certain circumstances; presumably when functions are internal to a compilation unit.)

Huon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to