Skip to content

Commit a8c96a6

Browse files
impl clear
1 parent 488cbca commit a8c96a6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

crates/bevy_ecs/src/storage/sparse_set.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,26 @@ impl ComponentSparseSet {
171171
}
172172

173173
/// Removes all of the values stored within.
174-
pub(crate) fn clear(&mut self) {}
174+
pub(crate) fn clear(&mut self) {
175+
let Self {
176+
entity_to_row,
177+
free_rows,
178+
buffer_len,
179+
buffer_capacity: _,
180+
column,
181+
} = self;
182+
183+
if let Some(drop) = column.data.drop {
184+
for row in entity_to_row.iter().filter_map(|row| row.map(|row| row.0)) {
185+
// SAFETY: We have &mut and clearing all rows. This value will never be accessed again.
186+
unsafe { drop(column.data.get_unchecked_mut(row.index()).promote()) }
187+
}
188+
}
189+
190+
free_rows.clear();
191+
entity_to_row.clear();
192+
*buffer_len = 0;
193+
}
175194

176195
/// Returns the number of component values in the sparse set.
177196
#[inline]

0 commit comments

Comments
 (0)