File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
crates/bevy_ecs/src/query Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -187,12 +187,19 @@ where
187
187
. map ( |index| self . world . archetypes [ ArchetypeId :: new ( index) ] . len ( ) )
188
188
. sum ( ) ;
189
189
190
- // n! / k!(n-k)! = (n*n-1*...*n-k+1) / k!
191
- let k_factorial: usize = ( 1 ..=K ) . product ( ) ;
192
- let max_permutations =
193
- ( 0 ..K ) . fold ( 1 , |n, i| n * ( max_size. saturating_sub ( i) ) ) / k_factorial;
190
+ if max_size < K {
191
+ return ( 0 , Some ( 0 ) ) ;
192
+ }
194
193
195
- ( 0 , Some ( max_permutations) )
194
+ // n! / k!(n-k)! = (n*n-1*...*n-k+1) / k!
195
+ let max_permutations = ( 0 ..K )
196
+ . try_fold ( 1usize , |n, i| n. checked_mul ( max_size - i) )
197
+ . map ( |n| {
198
+ let k_factorial: usize = ( 1 ..=K ) . product ( ) ;
199
+ n / k_factorial
200
+ } ) ;
201
+
202
+ ( 0 , max_permutations)
196
203
}
197
204
}
198
205
You can’t perform that action at this time.
0 commit comments