Skip to content

Commit

Permalink
hunt down redundant closes all over the place
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Apr 8, 2024
1 parent 1c5238c commit 0008cc6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 47 deletions.
28 changes: 11 additions & 17 deletions crates/re_query_cache/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,7 @@ impl CacheBucket {

/// Iterate over the batches of the specified non-optional component.
#[inline]
pub fn iter_component<C: Component + Send + Sync + 'static>(
&self,
) -> Option<impl Iterator<Item = &[C]>> {
pub fn iter_component<C: Component>(&self) -> Option<impl Iterator<Item = &[C]>> {
let data = self
.components
.get(&C::name())
Expand All @@ -746,9 +744,7 @@ impl CacheBucket {

/// Iterate over the batches of the specified optional component.
#[inline]
pub fn iter_component_opt<C: Component + Send + Sync + 'static>(
&self,
) -> Option<impl Iterator<Item = &[Option<C>]>> {
pub fn iter_component_opt<C: Component>(&self) -> Option<impl Iterator<Item = &[Option<C>]>> {
let data = self
.components
.get(&C::name())
Expand Down Expand Up @@ -823,15 +819,15 @@ impl CacheBucket {

/// Get the raw batches for the specified non-optional component.
#[inline]
pub fn component<C: Component + Send + Sync + 'static>(&self) -> Option<&FlatVecDeque<C>> {
pub fn component<C: Component>(&self) -> Option<&FlatVecDeque<C>> {
self.components
.get(&C::name())
.and_then(|data| data.as_any().downcast_ref::<FlatVecDeque<C>>())
}

/// Range over the batches of the specified non-optional component.
#[inline]
pub fn range_component<C: Component + Send + Sync + 'static>(
pub fn range_component<C: Component>(
&self,
entry_range: Range<usize>,
) -> Option<impl Iterator<Item = &[C]>> {
Expand All @@ -844,17 +840,15 @@ impl CacheBucket {

/// Get the raw batches for the specified optional component.
#[inline]
pub fn component_opt<C: Component + Send + Sync + 'static>(
&self,
) -> Option<&FlatVecDeque<Option<C>>> {
pub fn component_opt<C: Component>(&self) -> Option<&FlatVecDeque<Option<C>>> {
self.components
.get(&C::name())
.and_then(|data| data.as_any().downcast_ref::<FlatVecDeque<Option<C>>>())
}

/// Range over the batches of the specified optional component.
#[inline]
pub fn range_component_opt<C: Component + Send + Sync + 'static>(
pub fn range_component_opt<C: Component>(
&self,
entry_range: Range<usize>,
) -> Option<impl Iterator<Item = &[Option<C>]>> {
Expand Down Expand Up @@ -934,8 +928,8 @@ macro_rules! impl_insert {
) -> ::re_query::Result<u64>
where
A: Archetype,
$($pov: Component + Send + Sync + 'static,)+
$($comp: Component + Send + Sync + 'static,)*
$($pov: Component,)+
$($comp: Component,)*
{
// NOTE: not `profile_function!` because we want them merged together.
re_tracing::profile_scope!("CacheBucket::insert", format!("arch={} pov={} comp={}", A::name(), $N, $M));
Expand Down Expand Up @@ -992,7 +986,7 @@ impl CacheBucket {
) -> ::re_query::Result<u64>
where
A: Archetype,
R1: Component + Send + Sync + 'static,
R1: Component,
{
self.insert_pov1_comp0::<A, R1>(query_time, arch_view)
}
Expand All @@ -1002,7 +996,7 @@ impl CacheBucket {
});

#[inline]
fn insert_component<A: Archetype, C: Component + Send + Sync + 'static>(
fn insert_component<A: Archetype, C: Component>(
&mut self,
at: usize,
arch_view: &ArchetypeView<A>,
Expand Down Expand Up @@ -1041,7 +1035,7 @@ impl CacheBucket {

/// This will insert an empty slice for a missing component (instead of N `None` values).
#[inline]
fn insert_component_opt<A: Archetype, C: Component + Send + Sync + 'static>(
fn insert_component_opt<A: Archetype, C: Component>(
&mut self,
at: usize,
arch_view: &ArchetypeView<A>,
Expand Down
4 changes: 2 additions & 2 deletions crates/re_query_cache/src/latest_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ macro_rules! impl_query_archetype_latest_at {
) -> ::re_query::Result<()>
where
A: Archetype + 'a,
$($pov: Component + Send + Sync + 'static,)+
$($comp: Component + Send + Sync + 'static,)*
$($pov: Component,)+
$($comp: Component,)*
F: FnMut(
(
(TimeInt, RowId),
Expand Down
12 changes: 6 additions & 6 deletions crates/re_query_cache/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Caches {
) -> ::re_query::Result<()>
where
A: Archetype + 'a,
R1: Component + Send + Sync + 'static,
R1: Component,
F: FnMut(((TimeInt, RowId), &[InstanceKey], &[R1])),
{
self.query_archetype_pov1_comp0::<A, R1, F>(store, query, entity_path, f)
Expand All @@ -60,8 +60,8 @@ macro_rules! impl_query_archetype {
) -> ::re_query::Result<()>
where
A: Archetype + 'a,
$($pov: Component + Send + Sync + 'static,)+
$($comp: Component + Send + Sync + 'static,)*
$($pov: Component,)+
$($comp: Component,)*
F: FnMut(
(
(TimeInt, RowId),
Expand Down Expand Up @@ -159,7 +159,7 @@ impl Caches {
) -> ::re_query::Result<()>
where
A: Archetype + 'a,
R1: Component + Send + Sync + 'static,
R1: Component,
F: FnMut(((TimeInt, RowId), &[InstanceKey], &[R1])),
{
self.query_archetype_with_history_pov1_comp0::<A, R1, F>(
Expand All @@ -186,8 +186,8 @@ macro_rules! impl_query_archetype_with_history {
) -> ::re_query::Result<()>
where
A: Archetype + 'a,
$($pov: Component + Send + Sync + 'static,)+
$($comp: Component + Send + Sync + 'static,)*
$($pov: Component,)+
$($comp: Component,)*
F: FnMut(
(
(TimeInt, RowId),
Expand Down
8 changes: 4 additions & 4 deletions crates/re_query_cache/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ macro_rules! impl_query_archetype_range {
) -> ::re_query::Result<()>
where
A: Archetype + 'a,
$($pov: Component + Send + Sync + 'static,)+
$($comp: Component + Send + Sync + 'static,)*
$($pov: Component,)+
$($comp: Component,)*
F: FnMut(
std::ops::Range<usize>,
(
Expand Down Expand Up @@ -218,8 +218,8 @@ macro_rules! impl_query_archetype_range {
) -> crate::Result<u64>
where
A: Archetype + 'a,
$($pov: Component + Send + Sync + 'static,)+
$($comp: Component + Send + Sync + 'static,)*
$($pov: Component,)+
$($comp: Component,)*
{
re_tracing::profile_scope!("fill");

Expand Down
24 changes: 8 additions & 16 deletions crates/re_query_cache2/src/latest_at/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl CachedLatestAtComponentResults {
/// Use [`PromiseResult::flatten`] to merge the results of resolving the promise and of
/// deserializing the data into a single one, if you don't need the extra flexibility.
#[inline]
pub fn to_dense<C: 'static + Component + Send + Sync>(
pub fn to_dense<C: Component>(
&self,
resolver: &PromiseResolver,
) -> PromiseResult<crate::Result<&[C]>> {
Expand All @@ -201,7 +201,7 @@ impl CachedLatestAtComponentResults {
/// Use [`PromiseResult::flatten`] to merge the results of resolving the promise and of
/// deserializing the data into a single one, if you don't need the extra flexibility.
#[inline]
pub fn iter_dense<C: 'static + Component + Send + Sync>(
pub fn iter_dense<C: Component>(
&self,
resolver: &PromiseResolver,
) -> PromiseResult<crate::Result<impl ExactSizeIterator<Item = &C>>> {
Expand All @@ -216,7 +216,7 @@ impl CachedLatestAtComponentResults {
/// Use [`PromiseResult::flatten`] to merge the results of resolving the promise and of
/// deserializing the data into a single one, if you don't need the extra flexibility.
#[inline]
pub fn to_sparse<C: 'static + Component + Send + Sync>(
pub fn to_sparse<C: Component>(
&self,
resolver: &PromiseResolver,
) -> PromiseResult<crate::Result<&[Option<C>]>> {
Expand All @@ -237,7 +237,7 @@ impl CachedLatestAtComponentResults {
/// Use [`PromiseResult::flatten`] to merge the results of resolving the promise and of
/// deserializing the data into a single one, if you don't need the extra flexibility.
#[inline]
pub fn iter_sparse<C: 'static + Component + Send + Sync>(
pub fn iter_sparse<C: Component>(
&self,
resolver: &PromiseResolver,
) -> PromiseResult<crate::Result<impl ExactSizeIterator<Item = Option<&C>>>> {
Expand All @@ -247,10 +247,7 @@ impl CachedLatestAtComponentResults {
}

impl CachedLatestAtComponentResults {
fn downcast_dense<C: 'static + Component + Send + Sync>(
&self,
cell: &DataCell,
) -> crate::Result<&[C]> {
fn downcast_dense<C: Component>(&self, cell: &DataCell) -> crate::Result<&[C]> {
// `OnceLock::get` is non-blocking -- this is a best-effort fast path in case the
// data has already been computed.
//
Expand All @@ -276,10 +273,7 @@ impl CachedLatestAtComponentResults {
downcast(&**cached)
}

fn downcast_sparse<C: 'static + Component + Send + Sync>(
&self,
cell: &DataCell,
) -> crate::Result<&[Option<C>]> {
fn downcast_sparse<C: Component>(&self, cell: &DataCell) -> crate::Result<&[Option<C>]> {
// `OnceLock::get` is non-blocking -- this is a best-effort fast path in case the
// data has already been computed.
//
Expand All @@ -306,9 +300,7 @@ impl CachedLatestAtComponentResults {
}
}

fn downcast<C: 'static + Component + Send + Sync>(
cached: &(dyn ErasedFlatVecDeque + Send + Sync),
) -> crate::Result<&[C]> {
fn downcast<C: Component>(cached: &(dyn ErasedFlatVecDeque + Send + Sync)) -> crate::Result<&[C]> {
let cached = cached
.as_any()
.downcast_ref::<FlatVecDeque<C>>()
Expand All @@ -324,7 +316,7 @@ fn downcast<C: 'static + Component + Send + Sync>(
Ok(cached.iter().next().unwrap())
}

fn downcast_opt<C: 'static + Component + Send + Sync>(
fn downcast_opt<C: Component>(
cached: &(dyn ErasedFlatVecDeque + Send + Sync),
) -> crate::Result<&[Option<C>]> {
let cached = cached
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ macro_rules! impl_process_archetype {
where
S: IdentifiedViewSystem,
A: Archetype + 'a,
$($pov: Component + Send + Sync + 'static,)+
$($comp: Component + Send + Sync + 'static,)*
$($pov: Component,)+
$($comp: Component,)*
F: FnMut(
&ViewerContext<'_>,
&EntityPath,
Expand Down

0 comments on commit 0008cc6

Please sign in to comment.