-
-
Notifications
You must be signed in to change notification settings - Fork 4k
[Merged by Bors] - small ecs cleanup and remove_bundle drop bugfix #2172
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7913179
remove special case value for ArchetypeGeneration
Frizi 17d092c
remove unnecessary usage of UnsafeCell around pointers in BlobVec
Frizi 738f075
drop sparse components in `remove_bundle` command
Frizi c933008
constify ArchetypeGeneration::initial
Frizi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
use std::{ | ||
alloc::{handle_alloc_error, Layout}, | ||
cell::UnsafeCell, | ||
ptr::NonNull, | ||
}; | ||
|
||
|
@@ -9,17 +8,17 @@ pub struct BlobVec { | |
item_layout: Layout, | ||
capacity: usize, | ||
len: usize, | ||
data: UnsafeCell<NonNull<u8>>, | ||
swap_scratch: UnsafeCell<NonNull<u8>>, | ||
data: NonNull<u8>, | ||
swap_scratch: NonNull<u8>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can confirm this |
||
drop: unsafe fn(*mut u8), | ||
} | ||
|
||
impl BlobVec { | ||
pub fn new(item_layout: Layout, drop: unsafe fn(*mut u8), capacity: usize) -> BlobVec { | ||
if item_layout.size() == 0 { | ||
BlobVec { | ||
swap_scratch: UnsafeCell::new(NonNull::dangling()), | ||
data: UnsafeCell::new(NonNull::dangling()), | ||
swap_scratch: NonNull::dangling(), | ||
data: NonNull::dangling(), | ||
capacity: usize::MAX, | ||
len: 0, | ||
item_layout, | ||
|
@@ -29,8 +28,8 @@ impl BlobVec { | |
let swap_scratch = NonNull::new(unsafe { std::alloc::alloc(item_layout) }) | ||
.unwrap_or_else(|| std::alloc::handle_alloc_error(item_layout)); | ||
let mut blob_vec = BlobVec { | ||
swap_scratch: UnsafeCell::new(swap_scratch), | ||
data: UnsafeCell::new(NonNull::dangling()), | ||
swap_scratch, | ||
data: NonNull::dangling(), | ||
capacity: 0, | ||
len: 0, | ||
item_layout, | ||
|
@@ -81,9 +80,7 @@ impl BlobVec { | |
) | ||
}; | ||
|
||
self.data = UnsafeCell::new( | ||
NonNull::new(new_data).unwrap_or_else(|| handle_alloc_error(new_layout)), | ||
); | ||
self.data = NonNull::new(new_data).unwrap_or_else(|| handle_alloc_error(new_layout)); | ||
} | ||
self.capacity = new_capacity; | ||
} | ||
|
@@ -132,7 +129,7 @@ impl BlobVec { | |
pub unsafe fn swap_remove_and_forget_unchecked(&mut self, index: usize) -> *mut u8 { | ||
debug_assert!(index < self.len()); | ||
let last = self.len - 1; | ||
let swap_scratch = (*self.swap_scratch.get()).as_ptr(); | ||
let swap_scratch = self.swap_scratch.as_ptr(); | ||
std::ptr::copy_nonoverlapping( | ||
self.get_unchecked(index), | ||
swap_scratch, | ||
|
@@ -170,7 +167,7 @@ impl BlobVec { | |
/// must ensure rust mutability rules are not violated | ||
#[inline] | ||
pub unsafe fn get_ptr(&self) -> NonNull<u8> { | ||
*self.data.get() | ||
self.data | ||
} | ||
|
||
pub fn clear(&mut self) { | ||
|
@@ -199,7 +196,7 @@ impl Drop for BlobVec { | |
array_layout(&self.item_layout, self.capacity) | ||
.expect("array layout should be valid"), | ||
); | ||
std::alloc::dealloc((*self.swap_scratch.get()).as_ptr(), self.item_layout); | ||
std::alloc::dealloc(self.swap_scratch.as_ptr(), self.item_layout); | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.