about summary refs log tree commit diff
path: root/src/test/codegen/stack-alloc-string-slice.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-02-03 15:36:04 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-02-03 20:11:20 -0800
commit1d921f557d6d9e509ce0d696d7b2178628989935 (patch)
treeeebe80ab3b8de14a572c83612362126e444b10ee /src/test/codegen/stack-alloc-string-slice.rs
parent61b2f3a4f0a27180a0cdc3b3343ac63cf86ff8cc (diff)
parent9a17f62947d0c079f1c877de4fe1dab5b2c500d9 (diff)
downloadrust-1d921f557d6d9e509ce0d696d7b2178628989935.tar.gz
rust-1d921f557d6d9e509ce0d696d7b2178628989935.zip
rollup merge of #21897: dotdash/rposition
The extra check caused by the expect() call can, in general, not be
optimized away, because the length of the iterator is unknown at compile
time, causing a noticable slow-down. Since the check only triggers if
the element isn't actually found in the iterator, i.e. it isn't
guaranteed to trigger for ill-behaved ExactSizeIterators, it seems
reasonable to switch to an implementation that doesn't need the check
and just always returns None if the value isn't found.

Benchmark:
````rust
let v: Vec<u8> = (0..1024*65).map(|_| 0).collect();
b.iter(|| {
    v.as_slice().iter().rposition(|&c| c == 1)
});
````

Before:
````
test rposition  ... bench:     49939 ns/iter (+/- 23)
````

After:
````
test rposition  ... bench:     33306 ns/iter (+/- 68)
````
Diffstat (limited to 'src/test/codegen/stack-alloc-string-slice.rs')
0 files changed, 0 insertions, 0 deletions