[Merged by Bors] - Remove broken DoubleEndedIterator impls on event iterators - #7469
Closed
tim-blackbird wants to merge 3 commits into
Closed
[Merged by Bors] - Remove broken DoubleEndedIterator impls on event iterators#7469tim-blackbird wants to merge 3 commits into
DoubleEndedIterator impls on event iterators#7469tim-blackbird wants to merge 3 commits into
Conversation
Contributor
Author
|
Not super sure what to write for the Migration Guide |
tim-blackbird
commented
Feb 2, 2023
Comment on lines
-272
to
+274
| if scale_factor_events.iter().next_back().is_some() || ui_scale.is_changed() { | ||
| if !scale_factor_events.is_empty() || ui_scale.is_changed() { | ||
| scale_factor_events.clear(); |
Contributor
Author
There was a problem hiding this comment.
.next_back().is_some() wasn't the right way to do this, but unless multiple scale_factor_events are sent in a frame it behaves the same way as is_empty with a clear.
Not a big deal.
alice-i-cecile
approved these changes
Feb 2, 2023
james7132
self-requested a review
February 3, 2023 05:35
joseph-gio
approved these changes
Feb 5, 2023
Member
|
bors r+ |
bors Bot
pushed a commit
that referenced
this pull request
Feb 5, 2023
The `DoubleEndedIterator` impls produce incorrect results on subsequent calls to `iter()` if the iterator is only partially consumed.
The following code shows what happens
```rust
fn next_back_is_bad() {
let mut events = Events::<TestEvent>::default();
events.send(TestEvent { i: 0 });
events.send(TestEvent { i: 1 });
events.send(TestEvent { i: 2 });
let mut reader = events.get_reader();
let mut iter = reader.iter(&events);
assert_eq!(iter.next_back(), Some(&TestEvent { i: 2 }));
assert_eq!(iter.next(), Some(&TestEvent { i: 0 }));
let mut iter = reader.iter(&events);
// `i: 2` event is returned twice! The `i: 1` event is missed.
assert_eq!(iter.next(), Some(&TestEvent { i: 2 }));
assert_eq!(iter.next(), None);
}
```
I don't think this can be fixed without adding some very convoluted bookkeeping.
## Migration Guide
`ManualEventIterator` and `ManualEventIteratorWithId` are no longer `DoubleEndedIterator`s.
Co-authored-by: devil-ira <justthecooldude@gmail.com>
|
Build failed: |
Aceeri
approved these changes
Feb 5, 2023
tim-blackbird
force-pushed
the
event-not-doubleendediterator
branch
from
February 5, 2023 11:57
fc152b8 to
140225e
Compare
Member
|
bors r+ |
bors Bot
pushed a commit
that referenced
this pull request
Feb 5, 2023
The `DoubleEndedIterator` impls produce incorrect results on subsequent calls to `iter()` if the iterator is only partially consumed.
The following code shows what happens
```rust
fn next_back_is_bad() {
let mut events = Events::<TestEvent>::default();
events.send(TestEvent { i: 0 });
events.send(TestEvent { i: 1 });
events.send(TestEvent { i: 2 });
let mut reader = events.get_reader();
let mut iter = reader.iter(&events);
assert_eq!(iter.next_back(), Some(&TestEvent { i: 2 }));
assert_eq!(iter.next(), Some(&TestEvent { i: 0 }));
let mut iter = reader.iter(&events);
// `i: 2` event is returned twice! The `i: 1` event is missed.
assert_eq!(iter.next(), Some(&TestEvent { i: 2 }));
assert_eq!(iter.next(), None);
}
```
I don't think this can be fixed without adding some very convoluted bookkeeping.
## Migration Guide
`ManualEventIterator` and `ManualEventIteratorWithId` are no longer `DoubleEndedIterator`s.
Co-authored-by: devil-ira <justthecooldude@gmail.com>
|
Pull request successfully merged into main. Build succeeded:
|
DoubleEndedIterator impls on event iteratorsDoubleEndedIterator impls on event iterators
2 tasks
bors Bot
pushed a commit
that referenced
this pull request
Feb 16, 2023
# Objective Motivated by #7469. `EventReader` iterators use the default implementations for `.nth()` and `.last()`, which includes iterating over and throwing out all events before the desired one. ## Solution Add specialized implementations for these methods that directly updates the unread event counter and returns a reference to the desired event. TODO: - [x] Add a unit test. - [x] ~~Add a benchmark, to see if the compiler was doing this automatically already.~~ *On second thought, this doesn't feel like a very useful thing to include in the benchmark suite.*
myreprise1
pushed a commit
to myreprise1/bevy
that referenced
this pull request
Feb 18, 2023
# Objective Motivated by bevyengine#7469. `EventReader` iterators use the default implementations for `.nth()` and `.last()`, which includes iterating over and throwing out all events before the desired one. ## Solution Add specialized implementations for these methods that directly updates the unread event counter and returns a reference to the desired event. TODO: - [x] Add a unit test. - [x] ~~Add a benchmark, to see if the compiler was doing this automatically already.~~ *On second thought, this doesn't feel like a very useful thing to include in the benchmark suite.*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
DoubleEndedIteratorimpls produce incorrect results on subsequent calls toiter()if the iterator is only partially consumed.The following code shows what happens
I don't think this can be fixed without adding some very convoluted bookkeeping.
Migration Guide
ManualEventIteratorandManualEventIteratorWithIdare no longerDoubleEndedIterators.