diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c009655..86c197a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## 0.6.1 - 2023-03-21 +### Fixed +- Querying with empty component views no longer iterates endlessly. It now iterates once for each entity filtered, despite no components being viewed. + ## 0.6.0 - 2023-03-20 ### Added - `resource` module containing types related to resources. diff --git a/Cargo.toml b/Cargo.toml index 8bf6935a..010fa929 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "brood" -version = "0.6.0" +version = "0.6.1" authors = ["Anders Evensen"] edition = "2021" rust-version = "1.65.0" diff --git a/src/query/result/reshape.rs b/src/query/result/reshape.rs index 3dda6384..17576556 100644 --- a/src/query/result/reshape.rs +++ b/src/query/result/reshape.rs @@ -13,8 +13,8 @@ pub trait Reshape { fn reshape(self) -> R; } -impl Reshape, Null> for iter::Repeat { - fn reshape(self) -> iter::Repeat { +impl Reshape>, Null> for iter::Take> { + fn reshape(self) -> iter::Take> { self } } diff --git a/src/query/result/sealed/mod.rs b/src/query/result/sealed/mod.rs index 16c87989..24c47453 100644 --- a/src/query/result/sealed/mod.rs +++ b/src/query/result/sealed/mod.rs @@ -14,7 +14,7 @@ pub trait Results { fn into_iterator(self) -> Self::Iterator; } -impl Results for iter::Repeat { +impl Results for iter::Take> { type View = view::Null; type Iterator = Self; diff --git a/src/query/view/sealed.rs b/src/query/view/sealed.rs index 2c759a86..cc3f8209 100644 --- a/src/query/view/sealed.rs +++ b/src/query/view/sealed.rs @@ -59,7 +59,7 @@ pub trait ViewsSealed<'a> { } impl<'a> ViewsSealed<'a> for Null { - type Results = iter::Repeat; + type Results = iter::Take>; } impl<'a, V, W> ViewsSealed<'a> for (V, W) diff --git a/src/registry/sealed/par_view.rs b/src/registry/sealed/par_view.rs index 51594c2b..8dd788ef 100644 --- a/src/registry/sealed/par_view.rs +++ b/src/registry/sealed/par_view.rs @@ -49,13 +49,13 @@ where impl<'a> CanonicalParViews<'a, view::Null, Null> for registry::Null { unsafe fn par_view( _columns: &[(*mut u8, usize)], - _length: usize, + length: usize, _archetype_identifier: archetype::identifier::Iter, ) -> >::ParResults where R: Registry, { - iter::repeatn(view::Null, usize::MAX) + iter::repeatn(view::Null, length) } } diff --git a/src/registry/sealed/view.rs b/src/registry/sealed/view.rs index 5a824201..496c77ed 100644 --- a/src/registry/sealed/view.rs +++ b/src/registry/sealed/view.rs @@ -69,13 +69,13 @@ where impl<'a> CanonicalViews<'a, view::Null, Null> for registry::Null { unsafe fn view( _columns: &[(*mut u8, usize)], - _length: usize, + length: usize, _archetype_identifier: archetype::identifier::Iter, ) -> >::Results where R: Registry, { - iter::repeat(view::Null) + iter::repeat(view::Null).take(length) } unsafe fn view_one( diff --git a/src/world/mod.rs b/src/world/mod.rs index 6fd83f34..fe254a51 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -1436,6 +1436,20 @@ mod tests { assert_eq!(b, &mut B('a')); } + #[test] + fn query_empty() { + let mut world = World::::new(); + + world.insert(entity!(B('a'), A(1))); + world.insert(entity!(A(2))); + world.insert(entity!(B('b'))); + world.insert(entity!()); + + let count = world.query(Query::::new()).iter.count(); + + assert_eq!(count, 4); + } + #[cfg(feature = "rayon")] #[test] fn par_query_refs() { @@ -1640,6 +1654,21 @@ mod tests { assert_eq!(b, &mut B('a')); } + #[cfg(feature = "rayon")] + #[test] + fn par_query_empty() { + let mut world = World::::new(); + + world.insert(entity!(B('a'), A(1))); + world.insert(entity!(A(2))); + world.insert(entity!(B('b'))); + world.insert(entity!()); + + let count = world.par_query(Query::::new()).iter.count(); + + assert_eq!(count, 4); + } + #[test] fn system_refs() { struct TestSystem;