refactor(input): more compact registry contains

This commit is contained in:
Nova
2023-01-14 20:29:33 -05:00
parent 6ca93ea24c
commit 8e9956abe1
2 changed files with 14 additions and 10 deletions

View File

@@ -26,6 +26,11 @@ impl<T: Send + Sync + ?Sized> Registry<T> {
.lock()
.insert(Arc::as_ptr(t) as *const () as usize, Arc::downgrade(t));
}
pub fn contains(&self, t: &T) -> bool {
self.0
.lock()
.contains_key(&(ptr::addr_of!(*t) as *const () as usize))
}
pub fn get_valid_contents(&self) -> Vec<Arc<T>> {
self.0
.lock()
@@ -65,6 +70,11 @@ impl<T: Send + Sync + ?Sized> OwnedRegistry<T> {
pub fn get_vec(&self) -> Vec<Arc<T>> {
self.0.lock().values().cloned().collect::<Vec<_>>()
}
pub fn contains(&self, t: &T) -> bool {
self.0
.lock()
.contains_key(&(ptr::addr_of!(*t) as *const () as usize))
}
pub fn remove(&self, t: &T) {
self.0
.lock()