about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-09-18 23:11:24 +0000
committerbors <bors@rust-lang.org>2025-09-18 23:11:24 +0000
commit2f4dfc753fd86c672aa4145940db075a8a149f17 (patch)
treef55f869496583097a736b7f088f3fe7bae1f64cf /src
parent7c275d09ea6b953d2cca169667184a7214bd14c7 (diff)
parenteb7abeb2614fb64f4d23afaa83df7380159b72c2 (diff)
downloadrust-2f4dfc753fd86c672aa4145940db075a8a149f17.tar.gz
rust-2f4dfc753fd86c672aa4145940db075a8a149f17.zip
Auto merge of #137122 - yotamofek:pr/std/iter-eq-exact-size, r=the8472
Specialize `Iterator::eq{_by}` for `TrustedLen` iterators

I'm sure I got some stuff wrong here, but opening this to get feedback and make sure it's a viable idea at all.

### Motivation
I had a piece of code that open-coded `Iterator::eq`, something like:
```rust
if current.len() != other.len()
    || current.iter().zip(other.iter()).any(|(a, b)| a != b) { ... }
```
... where both `current` and `other` are slices of the same type.
Changing the code to use `current.iter().eq(other)` made it a lot slower, since it wasn't checking the length of the two slices beforehand anymore, which in this instance made a big difference in perf. So I thought I'd see if I can improve `Iterator::eq`.

### Questions
1. I can't specialize for `ExactSizeIterator`, I think it's a limitation of `min_specialization` but not sure exactly why. Is specializing for `TrustedLen` good enough?
2. Should I make a codegen test for this? If so, then how? (I manually checked the assembly to make sure it works as expected)
3. Where should I put `SpecIterCompare`?
4. Can I get a perf run for this, please? I think the compiler uses this in a few places, so it might have an affect.
Diffstat (limited to 'src')
0 files changed, 0 insertions, 0 deletions