On 20/06/14 02:02 PM, Josh Haberman wrote: > Does Rust have any way of optimizing away repeated calls to the same > function where possible? Like GCC's "pure" function attribute? > > To get a little more crazy, say you're working with a Map. Sometimes > it's convenient to write code like this: > > if (map.contains_key(foo)) { > let val = map.get(foo); > // ... > } > > This code, naively compiled, would perform two lookups. But only one is > logically required, and caching the lookup would only require a single > pointer. > > Is there any reasonable scenario under which the compiler could decide > to allocate stack space to cache that lookup, so that the code above > would be optimized to only perform one lookup? > > Josh
Rust has no way to mark effects. LLVM is able to infer the readonly, readnone and nounwind attributes in some cases, but not most.
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev