On Fri, Nov 8, 2013 at 6:06 PM, Igor Bukanov <i...@mir2.org> 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.
>

The only way you could avoid pointer indirection is by making the element
length part of the type, like fixed-size vectors. For strings, there's not
really a clearly meaningful element length (bytes? code points? graphemes?).

An alternate vector/string doing small string optimization makes more sense
to me.
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to