Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ impl OrderedRelationshipSourceCollection for Vec<Entity> {

fn place_most_recent(&mut self, index: usize) {
if let Some(entity) = self.pop() {
let index = index.min(self.len() - 1);
let index = index.min(self.len().saturating_sub(1));
self.insert(index, entity);
}
}

fn place(&mut self, entity: Entity, index: usize) {
if let Some(current) = <[Entity]>::iter(self).position(|e| *e == entity) {
// The len is at least 1, so the subtraction is safe.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment suggests the - 1 should always be safe, so does it indicate something else wrong?

Noting that I approve of the change to saturating_sub generally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line here IMO cannot fail, as the position call cannot return Some if there are no items to filter.
The bugfix is thus in the other line that was changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok that makes sense. This line was just changed while he was here.

let index = index.min(self.len() - 1);
let index = index.min(self.len().saturating_sub(1));
Vec::remove(self, current);
self.insert(index, entity);
};
Expand Down