On 11/8/13 3:06 PM, Igor Bukanov wrote:
On 8 November 2013 23:10, Oren Ben-Kiki <o...@ben-kiki.org> 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.

For one, you can pass substrings as `&str`. Those can't be optimized away so easily.

Patrick
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to