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-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to