Skip to content

Commit

Permalink
Provide better size_hint for QueryIter (bevyengine#1697)
Browse files Browse the repository at this point in the history
This PR overrides the default size_hint for QueryIter.
This is mainly done to provide inline documentation of Issue bevyengine#1686.
  • Loading branch information
MinerSebas committed Mar 19, 2021
1 parent dd4a196 commit c78b76b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/bevy_ecs/src/query/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ where
}
}
}

// NOTE: For unfiltered Queries this should actually return a exact size hint,
// to fulfil the ExactSizeIterator invariant, but this isn't practical without specialization.
// For more information see Issue #1686.
fn size_hint(&self) -> (usize, Option<usize>) {
let max_size = self
.query_state
.matched_archetypes
.ones()
.map(|index| self.world.archetypes[ArchetypeId::new(index)].len())
.sum();

(0, Some(max_size))
}
}

// NOTE: We can cheaply implement this for unfiltered Queries because we have:
Expand Down

0 comments on commit c78b76b

Please sign in to comment.