Hi,
indexing operations check boundaries. Compiler (LLVM backend) is capable
of removing some of them, sometimes, but generally indexed accesses
tends to be slower in comparison to iteration using the Iterator<T>.
Multiple mutable references are not only bad for multithreading and data
races but also they create more aliases that prevent optimizations.
Moreover, single-threaded code can be turned into multi-threaded easily
if you follow stricter rules from the start.
http://doc.rust-lang.org/guide.html#ownership,-borrowing,-and-lifetimes
Multiple mutable borrows from a same vector is currently one of the
biggest weaknesses of Rust. There are some proposals to cope with it but
I personally do not know what is the current state of the matter.
Large return values are placed in preallocated space, the same way as
RVO works in C++.
http://doc.rust-lang.org/guide-pointers.html#returning-pointers
JK
On 19.9.2014 09:39, silvio wrote:
Hi Rust,
I've recently tried to investigate rust's claim of being fast and had a
look at debian shootout.
A particular program I took a looked at is the n-body problem in which
you have to loop over pairs of bodies to calculate their gravitational
attraction. What struck me as strange was the number of indexing operations.
bodies[i]
bodies[j]
bodies[i]
bodies[j]
...
Now I don't know if the compiler is smart enough to optimize this away.
However, it seems generally impossible to make references.
let mut body_i = bodies.someMethod(i)
let mut body_j = bodies.someMethod(j)
So how is this usually done?
Why are multiple mutable references to the same object not allowed. To
achieve safe memory you only need to guarantee that different threads
don't write/read from/to the same memory location at the same time and
that is handled via ownership. (borrowed) references & don't have
ownership. Additionally, you need to ensure that all references not only
mut are not usable anymore until you can transfer ownership. So, I don't
understand why mut and not mut are treated differently.
An other small thing. I read that you should always return a type directly.
fn foo(args) -> big_struct
Does this mean that all return values are secretly pointers passed to
the function except for things that fit into registers?
regards
silvio
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev