mozilla/rust — pull request #13349 by stepancheg (2014-04-05 23:43:24+00:00)
Title: Optimize Once::doit when initialization is already completed

Load is much cheaper than fetch_add, at least on x86_64.

Verified with this test:

```
static mut o: one::Once = one::ONCE_INIT;
loop {
unsafe {
let start = time::precise_time_ns();
let iters = 50000000u64;
for _ in range(0, iters) {
o.doit(||{
println!("once!");
});
}
let end = time::precise_time_ns();
let ps_per_iter = 1000 * (end - start) / iters;
println!("{} ps per iter", ps_per_iter);
}
}
```

Test executed on Mac, Intel Core i7 2GHz. Result is 700ps per iteration
with patch applied, and 17000ps per iteration without patch.