Skip to content

Commit

Permalink
Prevent creation of superfluous empty table
Browse files Browse the repository at this point in the history
  • Loading branch information
omaskery committed Dec 22, 2024
1 parent 2027700 commit 8857d67
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/bevy_ecs/src/storage/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ impl Tables {
component_ids: &[ComponentId],
components: &Components,
) -> TableId {
if component_ids.is_empty() {
return TableId::empty();
}

let tables = &mut self.tables;
let (_key, value) = self
.table_ids
Expand Down Expand Up @@ -816,14 +820,27 @@ mod tests {
component::{Component, Components, Tick},
entity::Entity,
ptr::OwningPtr,
storage::{Storages, TableBuilder, TableRow},
storage::{Storages, TableBuilder, TableRow, Tables, TableId},
};
#[cfg(feature = "track_change_detection")]
use core::panic::Location;

#[derive(Component)]
struct W<T>(T);

#[test]
fn only_one_empty_table() {
let components = Components::default();
let mut tables = Tables::default();

let component_ids = &[];
let table_id = unsafe {
tables.get_id_or_insert(component_ids, &components)
};

assert_eq!(table_id, TableId::empty());
}

#[test]
fn table() {
let mut components = Components::default();
Expand Down

0 comments on commit 8857d67

Please sign in to comment.