Skip to content

Commit

Permalink
Remove unnecessary borrow calls on bitset reference in restricted sto…
Browse files Browse the repository at this point in the history
…rage
  • Loading branch information
Imberflur committed Sep 16, 2023
1 parent eecf83a commit 276450e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/storage/restrict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ where
type Value = (&'rf C::Storage, &'rf Fetch<'rf, EntitiesRes>, &'rf BitSet);

unsafe fn open(self) -> (Self::Mask, Self::Value) {
let bitset = self.bitset.borrow();
(bitset, (self.data.borrow(), self.entities, bitset))
(
self.bitset,
(self.data.borrow(), self.entities, self.bitset),
)
}

unsafe fn get<'next>(value: &'next mut Self::Value, id: Index) -> Self::Type<'next> {
Expand Down Expand Up @@ -154,8 +156,10 @@ where
);

unsafe fn open(self) -> (Self::Mask, Self::Value) {
let bitset = self.bitset.borrow();
(bitset, (self.data.borrow_mut(), self.entities, bitset))
(
self.bitset,
(self.data.borrow_mut(), self.entities, self.bitset),
)
}

unsafe fn get<'next>(value: &'next mut Self::Value, id: Index) -> Self::Type<'next> {
Expand Down Expand Up @@ -191,8 +195,10 @@ where
type Value = (&'rf C::Storage, &'rf Fetch<'rf, EntitiesRes>, &'rf BitSet);

unsafe fn open(self) -> (Self::Mask, Self::Value) {
let bitset = self.bitset.borrow();
(bitset, (self.data.borrow(), self.entities, bitset))
(
self.bitset,
(self.data.borrow(), self.entities, self.bitset),
)
}

unsafe fn get(value: &mut Self::Value, id: Index) -> Self::Type {
Expand Down Expand Up @@ -362,8 +368,10 @@ where
type Value = (&'rf C::Storage, &'rf Fetch<'rf, EntitiesRes>, &'rf BitSet);

unsafe fn open(self) -> (Self::Mask, Self::Value) {
let bitset = self.bitset.borrow();
(bitset, (self.data.borrow(), self.entities, bitset))
(
self.bitset,
(self.data.borrow(), self.entities, self.bitset),
)
}

unsafe fn get(value: &Self::Value, id: Index) -> Self::Type {
Expand Down Expand Up @@ -603,7 +611,7 @@ where
///
/// Functions similar to the normal `Storage::get` implementation.
pub fn get_other(&self, entity: Entity) -> Option<&C> {
if self.bitset.borrow().contains(entity.id()) && self.entities.is_alive(entity) {
if self.bitset.contains(entity.id()) && self.entities.is_alive(entity) {
// SAFETY:We just checked the mask.
Some(unsafe { self.storage.get(entity.id()) })
} else {
Expand Down

0 comments on commit 276450e

Please sign in to comment.