about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2024-02-16 13:49:29 -0800
committerJosh Stone <jistone@redhat.com>2024-02-16 13:49:29 -0800
commit974bc455ee2d623ecda20e86ceed5907a47630e0 (patch)
treea7bd0d5bdcbe3402266efc0e5744f0e1b41568fe /compiler/rustc_data_structures/src
parentae9d7b0c6434b27e4e2effe8f05b16d37e7ef33f (diff)
downloadrust-974bc455ee2d623ecda20e86ceed5907a47630e0.tar.gz
rust-974bc455ee2d623ecda20e86ceed5907a47630e0.zip
Specialize flattening iterators with only one inner item
For iterators like `Once` and `option::IntoIter` that only ever have a
single item at most, the front and back iterator states in `FlatMap` and
`Flatten` are a waste, as they're always consumed already. We can use
specialization for these types to simplify the iterator methods.

It's a somewhat common pattern to use `flatten()` for options and
results, even recommended by [multiple][1] [clippy][2] [lints][3]. The
implementation is more efficient with `filter_map`, as mentioned in
[clippy#9377], but this new specialization should close some of that
gap for existing code that flattens.

[1]: https://rust-lang.github.io/rust-clippy/master/#filter_map_identity
[2]: https://rust-lang.github.io/rust-clippy/master/#option_filter_map
[3]: https://rust-lang.github.io/rust-clippy/master/#result_filter_map
[clippy#9377]: https://github.com/rust-lang/rust-clippy/issues/9377
Diffstat (limited to 'compiler/rustc_data_structures/src')
0 files changed, 0 insertions, 0 deletions