diff options
| author | Björn Steinbrink <bsteinbr@gmail.com> | 2015-02-03 16:54:06 +0100 |
|---|---|---|
| committer | Björn Steinbrink <bsteinbr@gmail.com> | 2015-02-03 16:54:06 +0100 |
| commit | 9a17f62947d0c079f1c877de4fe1dab5b2c500d9 (patch) | |
| tree | c173d432fbc6cd1158f504cf69794ba45e545930 /src/test/codegen/stack-alloc-string-slice.rs | |
| parent | 3d072a193bfcb76206aab576049e696d6d8db25d (diff) | |
| download | rust-9a17f62947d0c079f1c877de4fe1dab5b2c500d9.tar.gz rust-9a17f62947d0c079f1c877de4fe1dab5b2c500d9.zip | |
Optimize 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
