Skip to content

Commit 1b821dc

Browse files
committed
Tweaks
1 parent 937f647 commit 1b821dc

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

crates/bevy_ecs/src/entity/remote_allocator.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! This module contains the guts of Bevy's entity allocator.
22
//!
33
//! Entity allocation needs to work concurrently and remotely.
4-
//! Remote allocations (where no reference to the world is held) is needed for async primarily for use.
4+
//! Remote allocations (where no reference to the world is held) is needed for long running tasks, such as loading assets on separate threads.
55
//! Non-remote, "normal" allocation needs to be as fast as possible while still supporting remote allocation.
66
//!
77
//! The allocator fundamentally is made of a cursor for the next fresh, never used [`EntityIndex`] and a free list.
8-
//! The free list is some collection that hold [`Entity`] values that were used and can be reused; they are "free"/available.
8+
//! The free list is a collection that holds [`Entity`] values that were used and can be reused; they are "free"/available.
99
//! If the free list is empty, it's really simple to just increment the fresh index cursor.
1010
//! The tricky part is implementing a remotely accessible free list.
1111
//!
@@ -18,7 +18,7 @@
1818
//! That means, we can have a much more efficient allocation scheme, far better than a linked list.
1919
//!
2020
//! For the free list, the list needs to be pinned in memory and yet grow-able.
21-
//! That's quire the pickle, but by splitting the growth over multiple arrays, this isn't so bad.
21+
//! That's quite the pickle, but by splitting the growth over multiple arrays, this isn't so bad.
2222
//! When the list needs to grow, we just *add* on another array to the buffer (instead of *replacing* the old one with a bigger one).
2323
//! These arrays are called [`Chunk`]s.
2424
//! This keeps everything pinned, and since we know the maximum size ahead of time, we can make this mapping very fast.
@@ -48,7 +48,6 @@ use super::{Entity, EntityIndex, EntitySetIterator};
4848

4949
/// This is the item we store in the free list.
5050
/// Effectively, this is a `MaybeUninit<Entity>` where uninit is represented by `Entity::PLACEHOLDER`.
51-
/// This is
5251
struct Slot {
5352
inner: SyncUnsafeCell<Entity>,
5453
}
@@ -258,7 +257,7 @@ impl FreeBuffer {
258257
///
259258
/// # Safety
260259
///
261-
/// [`set`](Self::set) must have been called on this index to initialize the its memory.
260+
/// [`set`](Self::set) must have been called on this index to initialize its memory.
262261
/// There must be a clear, strict order between this call and the previous uses of this `full_index`.
263262
/// Otherwise, the compiler will make unsound optimizations.
264263
unsafe fn get(&self, full_index: u32) -> Entity {
@@ -473,10 +472,13 @@ impl FreeCount {
473472
success: Ordering,
474473
failure: Ordering,
475474
) -> Result<(), FreeCountState> {
476-
self.0
475+
match self
476+
.0
477477
.compare_exchange(expected_current_state.0, target_state.0, success, failure)
478-
.map(|_| ())
479-
.map_err(FreeCountState)
478+
{
479+
Ok(_) => Ok(()),
480+
Err(val) => Err(FreeCountState(val)),
481+
}
480482
}
481483
}
482484

@@ -557,7 +559,7 @@ impl FreeList {
557559
// SAFETY: This was less then `len`, so it must have been `set` via `free` before.
558560
// There is a strict memory ordering of this use of the index because the length is only decreasing.
559561
// That means there is only one use of this index since the last call to `free`.
560-
// The only time it the length increases is during `free`, which the caller ensures has a "happened before" relationship with this call.
562+
// The only time the length increases is during `free`, which the caller ensures has a "happened before" relationship with this call.
561563
Some(unsafe { self.buffer.get(index) })
562564
}
563565

0 commit comments

Comments
 (0)