Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Add a method for accessing the width of a Table #6249

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/query/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> QueryIterationCursor<'w, 's,
// `fetch_state`/`filter_state` are the states that `fetch/filter` were initialized with
Q::set_table(&mut self.fetch, &query_state.fetch_state, table);
F::set_table(&mut self.filter, &query_state.filter_state, table);
self.current_len = table.len();
self.current_len = table.entity_count();
self.current_index = 0;
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
Q::set_table(&mut fetch, &self.fetch_state, table);
F::set_table(&mut filter, &self.filter_state, table);

for table_index in 0..table.len() {
for table_index in 0..table.entity_count() {
if !F::table_filter_fetch(&mut filter, table_index) {
continue;
}
Expand Down Expand Up @@ -984,9 +984,9 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
for table_id in &self.matched_table_ids {
let table = &tables[*table_id];
let mut offset = 0;
while offset < table.len() {
while offset < table.entity_count() {
let func = func.clone();
let len = batch_size.min(table.len() - offset);
let len = batch_size.min(table.entity_count() - offset);
let task = async move {
let mut fetch = Q::init_fetch(
world,
Expand Down
26 changes: 18 additions & 8 deletions crates/bevy_ecs/src/storage/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Table {
row: usize,
new_table: &mut Table,
) -> TableMoveResult {
debug_assert!(row < self.len());
debug_assert!(row < self.entity_count());
let is_last = row == self.entities.len() - 1;
let new_row = new_table.allocate(self.entities.swap_remove(row));
for (component_id, column) in self.columns.iter_mut() {
Expand Down Expand Up @@ -294,7 +294,7 @@ impl Table {
row: usize,
new_table: &mut Table,
) -> TableMoveResult {
debug_assert!(row < self.len());
debug_assert!(row < self.entity_count());
let is_last = row == self.entities.len() - 1;
let new_row = new_table.allocate(self.entities.swap_remove(row));
for (component_id, column) in self.columns.iter_mut() {
Expand Down Expand Up @@ -325,7 +325,7 @@ impl Table {
row: usize,
new_table: &mut Table,
) -> TableMoveResult {
debug_assert!(row < self.len());
debug_assert!(row < self.entity_count());
let is_last = row == self.entities.len() - 1;
let new_row = new_table.allocate(self.entities.swap_remove(row));
for (component_id, column) in self.columns.iter_mut() {
Expand Down Expand Up @@ -388,13 +388,23 @@ impl Table {
}

#[inline]
pub fn capacity(&self) -> usize {
pub fn entity_count(&self) -> usize {
self.entities.len()
}

#[inline]
pub fn component_count(&self) -> usize {
self.columns.len()
}

#[inline]
pub fn entity_capacity(&self) -> usize {
self.entities.capacity()
}

#[inline]
pub fn len(&self) -> usize {
self.entities.len()
pub fn component_capacity(&self) -> usize {
self.columns.capacity()
}

#[inline]
Expand Down Expand Up @@ -565,7 +575,7 @@ mod tests {
};
}

assert_eq!(table.capacity(), 256);
assert_eq!(table.len(), 200);
assert_eq!(table.entity_capacity(), 256);
assert_eq!(table.entity_count(), 200);
}
}