]> git.lizzy.rs Git - rust.git/commit
auto merge of #8590 : blake2-ppc/rust/std-str, r=alexcrichton
authorbors <bors@rust-lang.org>
Thu, 22 Aug 2013 04:51:30 +0000 (21:51 -0700)
committerbors <bors@rust-lang.org>
Thu, 22 Aug 2013 04:51:30 +0000 (21:51 -0700)
commitf1132496dddbdd88f321a7919eec3d65136b3f75
tree06c11f35f1aa7b99f4c7a3f4f0f6e1294716753c
parent8e776c75e9694c2e1711943652c64a5e076afa8f
parent93de60e511d15b61a490ed690dee15c923ff9538
auto merge of #8590 : blake2-ppc/rust/std-str, r=alexcrichton

Implement CharIterator as a separate struct, so that it can be .clone()'d. Fix `.char_range_at_reverse` so that it performs better, closer to the forwards version. This makes the reverse iterators and users like `.rfind()` perform better.

    Before
    test str::bench::char_iterator ... bench: 146 ns/iter (+/- 0)
    test str::bench::char_iterator_ascii ... bench: 397 ns/iter (+/- 49)
    test str::bench::char_iterator_rev ... bench: 576 ns/iter (+/- 8)
    test str::bench::char_offset_iterator ... bench: 128 ns/iter (+/- 2)
    test str::bench::char_offset_iterator_rev ... bench: 425 ns/iter (+/- 59)

    After
    test str::bench::char_iterator ... bench: 130 ns/iter (+/- 1)
    test str::bench::char_iterator_ascii ... bench: 307 ns/iter (+/- 5)
    test str::bench::char_iterator_rev ... bench: 185 ns/iter (+/- 8)
    test str::bench::char_offset_iterator ... bench: 131 ns/iter (+/- 13)
    test str::bench::char_offset_iterator_rev ... bench: 183 ns/iter (+/- 2)

To be able to use a string slice to represent the CharIterator, a function `slice_unchecked` is added, that does the same as `slice_bytes` but without any boundary checks.

It would be possible to implement CharIterator with pointer arithmetic to make it *much more efficient*, but since vec iterator is still improving, it's too early to attempt to re-implement it in other places. Hopefully CharIterator can be implemented on top of vec iterator without any unsafe code later.

Additional changes fix the documentation about null termination.
src/libstd/str.rs