Skip to content

Commit 63b834a

Browse files
ecoskeytigregalis
authored andcommitted
rename ThinColumn to Column (bevyengine#21427)
# Objective - Now that we've removed Column, there's not really a reason for ThinColumn to have a special name ## Solution - Rename ThinColumn to Column - fix docs ## Testing - compiles
1 parent bdd436e commit 63b834a

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

crates/bevy_ecs/src/archetype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl Archetype {
425425
},
426426
);
427427
// NOTE: the `table_components` are sorted AND they were inserted in the `Table` in the same
428-
// sorted order, so the index of the `ThinColumn` in the `Table` is the same as the index of the
428+
// sorted order, so the index of the `Column` in the `Table` is the same as the index of the
429429
// component in the `table_components` vector
430430
component_index
431431
.entry(component_id)

crates/bevy_ecs/src/storage/sparse_set.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
component::{CheckChangeTicks, ComponentId, ComponentInfo, ComponentTicks, Tick, TickCells},
44
entity::{Entity, EntityRow},
55
query::DebugCheckedUnwrap,
6-
storage::{AbortOnPanic, TableRow, ThinColumn, VecExtensions},
6+
storage::{AbortOnPanic, Column, TableRow, VecExtensions},
77
};
88
use alloc::{boxed::Box, vec::Vec};
99
use bevy_ptr::{OwningPtr, Ptr};
@@ -120,7 +120,7 @@ impl<I: SparseSetIndex, V> SparseArray<I, V> {
120120
#[derive(Debug)]
121121
pub struct ComponentSparseSet {
122122
/// Capacity and length match those of `entities`.
123-
dense: ThinColumn,
123+
dense: Column,
124124
// Internally this only relies on the Entity index to keep track of where the component data is
125125
// stored for entities that are alive. The generation is not required, but is stored
126126
// in debug builds to validate that access is correct.
@@ -137,7 +137,7 @@ impl ComponentSparseSet {
137137
pub(crate) fn new(component_info: &ComponentInfo, capacity: usize) -> Self {
138138
let entities = Vec::with_capacity(capacity);
139139
Self {
140-
dense: ThinColumn::with_capacity(component_info, entities.capacity()),
140+
dense: Column::with_capacity(component_info, entities.capacity()),
141141
entities,
142142
sparse: Default::default(),
143143
}

crates/bevy_ecs/src/storage/table/column.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ use core::{mem::needs_drop, panic::Location};
77

88
/// A type-erased contiguous container for data of a homogeneous type.
99
///
10-
/// Conceptually, a `ThinColumn` is very similar to a type-erased `Box<[T]>`.
10+
/// Conceptually, a `Column` is very similar to a type-erased `Box<[T]>`.
1111
/// It also stores the change detection ticks for its components, kept in two separate
1212
/// contiguous buffers internally. An element shares its data across these buffers by using the
1313
/// same index (i.e. the entity at row 3 has it's data at index 3 and its change detection ticks at index 3).
1414
///
15-
/// Like many other low-level storage types, `ThinColumn` has a limited and highly unsafe
15+
/// Like many other low-level storage types, `Column` has a limited and highly unsafe
1616
/// interface. It's highly advised to use higher level types and their safe abstractions
17-
/// instead of working directly with `ThinColumn`.
17+
/// instead of working directly with `Column`.
1818
///
19-
/// For performance reasons, `ThinColumn` does not does not store it's capacity and length.
19+
/// For performance reasons, `Column` does not does not store it's capacity and length.
2020
/// This type is used by [`Table`] and [`ComponentSparseSet`], where the corresponding capacity
2121
/// and length can be found.
2222
///
2323
/// [`ComponentSparseSet`]: crate::storage::ComponentSparseSet
2424
#[derive(Debug)]
25-
pub struct ThinColumn {
25+
pub struct Column {
2626
pub(super) data: BlobArray,
2727
pub(super) added_ticks: ThinArrayPtr<UnsafeCell<Tick>>,
2828
pub(super) changed_ticks: ThinArrayPtr<UnsafeCell<Tick>>,
2929
pub(super) changed_by: MaybeLocation<ThinArrayPtr<UnsafeCell<&'static Location<'static>>>>,
3030
}
3131

32-
impl ThinColumn {
33-
/// Create a new [`ThinColumn`] with the given `capacity`.
32+
impl Column {
33+
/// Create a new [`Column`] with the given `capacity`.
3434
pub fn with_capacity(component_info: &ComponentInfo, capacity: usize) -> Self {
3535
Self {
3636
// SAFETY: The components stored in this columns will match the information in `component_info`
@@ -137,7 +137,7 @@ impl ThinColumn {
137137
data
138138
}
139139

140-
/// Call [`realloc`](std::alloc::realloc) to expand / shrink the memory allocation for this [`ThinColumn`]
140+
/// Call [`realloc`](std::alloc::realloc) to expand / shrink the memory allocation for this [`Column`]
141141
///
142142
/// # Panics
143143
/// - Panics if the any of the new capacity overflows `isize::MAX` bytes.
@@ -159,7 +159,7 @@ impl ThinColumn {
159159
.map(|changed_by| changed_by.realloc(current_capacity, new_capacity));
160160
}
161161

162-
/// Call [`alloc`](std::alloc::alloc) to allocate memory for this [`ThinColumn`]
162+
/// Call [`alloc`](std::alloc::alloc) to allocate memory for this [`Column`]
163163
/// The caller should make sure their saved `capacity` value is updated to `new_capacity` after this operation.
164164
///
165165
/// # Panics
@@ -233,7 +233,7 @@ impl ThinColumn {
233233
#[inline]
234234
pub(crate) unsafe fn initialize_from_unchecked(
235235
&mut self,
236-
other: &mut ThinColumn,
236+
other: &mut Column,
237237
other_last_element_index: usize,
238238
src_row: TableRow,
239239
dst_row: TableRow,
@@ -302,7 +302,7 @@ impl ThinColumn {
302302
}
303303

304304
/// Because this method needs parameters, it can't be the implementation of the `Drop` trait.
305-
/// The owner of this [`ThinColumn`] must call this method with the correct information.
305+
/// The owner of this [`Column`] must call this method with the correct information.
306306
///
307307
/// # Safety
308308
/// - `len` is indeed the length of the column
@@ -330,32 +330,32 @@ impl ThinColumn {
330330
self.data.drop_last_element(last_element_index);
331331
}
332332

333-
/// Get a slice to the data stored in this [`ThinColumn`].
333+
/// Get a slice to the data stored in this [`Column`].
334334
///
335335
/// # Safety
336-
/// - `T` must match the type of data that's stored in this [`ThinColumn`]
336+
/// - `T` must match the type of data that's stored in this [`Column`]
337337
/// - `len` must match the actual length of this column (number of elements stored)
338338
pub unsafe fn get_data_slice<T>(&self, len: usize) -> &[UnsafeCell<T>] {
339339
self.data.get_sub_slice(len)
340340
}
341341

342-
/// Get a slice to the added [`ticks`](Tick) in this [`ThinColumn`].
342+
/// Get a slice to the added [`ticks`](Tick) in this [`Column`].
343343
///
344344
/// # Safety
345345
/// - `len` must match the actual length of this column (number of elements stored)
346346
pub unsafe fn get_added_ticks_slice(&self, len: usize) -> &[UnsafeCell<Tick>] {
347347
self.added_ticks.as_slice(len)
348348
}
349349

350-
/// Get a slice to the changed [`ticks`](Tick) in this [`ThinColumn`].
350+
/// Get a slice to the changed [`ticks`](Tick) in this [`Column`].
351351
///
352352
/// # Safety
353353
/// - `len` must match the actual length of this column (number of elements stored)
354354
pub unsafe fn get_changed_ticks_slice(&self, len: usize) -> &[UnsafeCell<Tick>] {
355355
self.changed_ticks.as_slice(len)
356356
}
357357

358-
/// Get a slice to the calling locations that last changed each value in this [`ThinColumn`]
358+
/// Get a slice to the calling locations that last changed each value in this [`Column`]
359359
///
360360
/// # Safety
361361
/// - `len` must match the actual length of this column (number of elements stored)

crates/bevy_ecs/src/storage/table/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl TableRow {
137137
// it must be the correct capacity to allocate, reallocate, and deallocate all columns. This
138138
// means the safety invariant must be enforced even in `TableBuilder`.
139139
pub(crate) struct TableBuilder {
140-
columns: SparseSet<ComponentId, ThinColumn>,
140+
columns: SparseSet<ComponentId, Column>,
141141
entities: Vec<Entity>,
142142
}
143143

@@ -150,12 +150,12 @@ impl TableBuilder {
150150
}
151151
}
152152

153-
/// Add a new column to the [`Table`]. Specify the component which will be stored in the [`column`](ThinColumn) using its [`ComponentId`]
153+
/// Add a new column to the [`Table`]. Specify the component which will be stored in the [`column`](Column) using its [`ComponentId`]
154154
#[must_use]
155155
pub fn add_column(mut self, component_info: &ComponentInfo) -> Self {
156156
self.columns.insert(
157157
component_info.id(),
158-
ThinColumn::with_capacity(component_info, self.entities.capacity()),
158+
Column::with_capacity(component_info, self.entities.capacity()),
159159
);
160160
self
161161
}
@@ -174,7 +174,7 @@ impl TableBuilder {
174174
/// in a [`World`].
175175
///
176176
/// Conceptually, a `Table` can be thought of as a `HashMap<ComponentId, Column>`, where
177-
/// each [`ThinColumn`] is a type-erased `Vec<T: Component>`. Each row corresponds to a single entity
177+
/// each [`Column`] is a type-erased `Vec<T: Component>`. Each row corresponds to a single entity
178178
/// (i.e. index 3 in Column A and index 3 in Column B point to different components on the same
179179
/// entity). Fetching components from a table involves fetching the associated column for a
180180
/// component type (via its [`ComponentId`]), then fetching the entity's row within that column.
@@ -188,7 +188,7 @@ impl TableBuilder {
188188
// it must be the correct capacity to allocate, reallocate, and deallocate all columns. This
189189
// means the safety invariant must be enforced even in `TableBuilder`.
190190
pub struct Table {
191-
columns: ImmutableSparseSet<ComponentId, ThinColumn>,
191+
columns: ImmutableSparseSet<ComponentId, Column>,
192192
entities: Vec<Entity>,
193193
}
194194

@@ -482,28 +482,28 @@ impl Table {
482482
})
483483
}
484484

485-
/// Fetches a read-only reference to the [`ThinColumn`] for a given [`Component`] within the table.
485+
/// Fetches a read-only reference to the [`Column`] for a given [`Component`] within the table.
486486
///
487487
/// Returns `None` if the corresponding component does not belong to the table.
488488
///
489489
/// [`Component`]: crate::component::Component
490490
#[inline]
491-
pub fn get_column(&self, component_id: ComponentId) -> Option<&ThinColumn> {
491+
pub fn get_column(&self, component_id: ComponentId) -> Option<&Column> {
492492
self.columns.get(component_id)
493493
}
494494

495-
/// Fetches a mutable reference to the [`ThinColumn`] for a given [`Component`] within the
495+
/// Fetches a mutable reference to the [`Column`] for a given [`Component`] within the
496496
/// table.
497497
///
498498
/// Returns `None` if the corresponding component does not belong to the table.
499499
///
500500
/// [`Component`]: crate::component::Component
501501
#[inline]
502-
pub(crate) fn get_column_mut(&mut self, component_id: ComponentId) -> Option<&mut ThinColumn> {
502+
pub(crate) fn get_column_mut(&mut self, component_id: ComponentId) -> Option<&mut Column> {
503503
self.columns.get_mut(component_id)
504504
}
505505

506-
/// Checks if the table contains a [`ThinColumn`] for a given [`Component`].
506+
/// Checks if the table contains a [`Column`] for a given [`Component`].
507507
///
508508
/// Returns `true` if the column is present, `false` otherwise.
509509
///
@@ -670,8 +670,8 @@ impl Table {
670670
}
671671
}
672672

673-
/// Iterates over the [`ThinColumn`]s of the [`Table`].
674-
pub fn iter_columns(&self) -> impl Iterator<Item = &ThinColumn> {
673+
/// Iterates over the [`Column`]s of the [`Table`].
674+
pub fn iter_columns(&self) -> impl Iterator<Item = &Column> {
675675
self.columns.values()
676676
}
677677

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Replaced `Column` with `ThinColumn`
3+
pull_requests: [21427]
4+
---
5+
6+
The low-level `Column` and `ThinColumn` types in `bevy_ecs` have been
7+
merged into a single type, now called `Column` but with the api
8+
of `ThinColumn`. This type does not keep track of its own allocated
9+
length, and only provides unsafe methods.

0 commit comments

Comments
 (0)