Skip to content

Commit

Permalink
introduce interior mutability before it becomes a pita
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Mar 20, 2024
1 parent 81ae401 commit a4d36cb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions crates/re_query_cache2/benches/latest_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn query_and_visit_points(
store: &DataStore,
paths: &[EntityPath],
) -> Vec<SavePoint> {
let mut resolver = PromiseResolver::default();
let resolver = PromiseResolver::default();

let timeline_frame_nr = Timeline::new("frame_nr", TimeType::Sequence);
let query = LatestAtQuery::new(timeline_frame_nr, NUM_FRAMES_POINTS as i64 / 2);
Expand All @@ -300,13 +300,13 @@ fn query_and_visit_points(
let colors = results.get_optional::<Color>();

let points = points
.iter_dense::<Position2D>(&mut resolver)
.iter_dense::<Position2D>(&resolver)
.flatten()
.unwrap()
.copied();

let colors = colors
.iter_dense::<Color>(&mut resolver)
.iter_dense::<Color>(&resolver)
.flatten()
.unwrap()
.copied();
Expand All @@ -332,7 +332,7 @@ fn query_and_visit_strings(
store: &DataStore,
paths: &[EntityPath],
) -> Vec<SaveString> {
let mut resolver = PromiseResolver::default();
let resolver = PromiseResolver::default();

let timeline_frame_nr = Timeline::new("frame_nr", TimeType::Sequence);
let query = LatestAtQuery::new(timeline_frame_nr, NUM_FRAMES_STRINGS as i64 / 2);
Expand All @@ -351,13 +351,13 @@ fn query_and_visit_strings(
let colors = results.get_optional::<Text>();

let points = points
.iter_dense::<Position2D>(&mut resolver)
.iter_dense::<Position2D>(&resolver)
.flatten()
.unwrap()
.copied();

let labels = colors
.iter_dense::<Text>(&mut resolver)
.iter_dense::<Text>(&resolver)
.flatten()
.unwrap()
.cloned();
Expand Down
8 changes: 4 additions & 4 deletions crates/re_query_cache2/examples/latest_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> anyhow::Result<()> {
let store = store()?;
eprintln!("store:\n{}", store.to_data_table()?);

let mut resolver = PromiseResolver::default();
let resolver = PromiseResolver::default();

let entity_path = "points";
let timeline = Timeline::new("frame_nr", TimeType::Sequence);
Expand Down Expand Up @@ -63,7 +63,7 @@ fn main() -> anyhow::Result<()> {
//
// Otherwise, this will trigger a deserialization and cache the result for next time.

let points = match points.iter_dense::<MyPoint>(&mut resolver).flatten() {
let points = match points.iter_dense::<MyPoint>(&resolver).flatten() {
PromiseResult::Pending => {
// Handle the fact that the data isn't ready appropriately.
return Ok(());
Expand All @@ -72,7 +72,7 @@ fn main() -> anyhow::Result<()> {
PromiseResult::Error(err) => return Err(err.into()),
};

let colors = match colors.iter_dense::<MyColor>(&mut resolver).flatten() {
let colors = match colors.iter_dense::<MyColor>(&resolver).flatten() {
PromiseResult::Pending => {
// Handle the fact that the data isn't ready appropriately.
return Ok(());
Expand All @@ -81,7 +81,7 @@ fn main() -> anyhow::Result<()> {
PromiseResult::Error(err) => return Err(err.into()),
};

let labels = match labels.iter_sparse::<MyLabel>(&mut resolver).flatten() {
let labels = match labels.iter_sparse::<MyLabel>(&resolver).flatten() {
PromiseResult::Pending => {
// Handle the fact that the data isn't ready appropriately.
return Ok(());
Expand Down
8 changes: 4 additions & 4 deletions crates/re_query_cache2/src/latest_at/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl CachedLatestAtComponentResults {
#[inline]
pub fn to_dense<C: 'static + Component + Send + Sync>(
&self,
resolver: &mut PromiseResolver,
resolver: &PromiseResolver,
) -> PromiseResult<crate::Result<&[C]>> {
if let Some(cell) = self.promise.as_ref() {
resolver
Expand All @@ -203,7 +203,7 @@ impl CachedLatestAtComponentResults {
#[inline]
pub fn iter_dense<C: 'static + Component + Send + Sync>(
&self,
resolver: &mut PromiseResolver,
resolver: &PromiseResolver,
) -> PromiseResult<crate::Result<impl ExactSizeIterator<Item = &C>>> {
self.to_dense(resolver)
.map(|data| data.map(|data| data.iter()))
Expand All @@ -218,7 +218,7 @@ impl CachedLatestAtComponentResults {
#[inline]
pub fn to_sparse<C: 'static + Component + Send + Sync>(
&self,
resolver: &mut PromiseResolver,
resolver: &PromiseResolver,
) -> PromiseResult<crate::Result<&[Option<C>]>> {
if let Some(cell) = self.promise.as_ref() {
resolver
Expand All @@ -239,7 +239,7 @@ impl CachedLatestAtComponentResults {
#[inline]
pub fn iter_sparse<C: 'static + Component + Send + Sync>(
&self,
resolver: &mut PromiseResolver,
resolver: &PromiseResolver,
) -> PromiseResult<crate::Result<impl ExactSizeIterator<Item = Option<&C>>>> {
self.to_sparse(resolver)
.map(|data| data.map(|data| data.iter().map(Option::as_ref)))
Expand Down
10 changes: 5 additions & 5 deletions crates/re_query_cache2/tests/latest_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ fn query_and_compare(
) {
re_log::setup_logging();

let mut resolver = PromiseResolver::default();
let resolver = PromiseResolver::default();

for _ in 0..3 {
let cached = caches.latest_at(
Expand All @@ -488,13 +488,13 @@ fn query_and_compare(

let cached_points = cached.get_required::<MyPoint>().unwrap();
let cached_point_data = cached_points
.to_dense::<MyPoint>(&mut resolver)
.to_dense::<MyPoint>(&resolver)
.flatten()
.unwrap();

let cached_colors = cached.get_optional::<MyColor>();
let cached_color_data = cached_colors
.to_sparse::<MyColor>(&mut resolver)
.to_sparse::<MyColor>(&resolver)
.flatten()
.unwrap();

Expand All @@ -507,13 +507,13 @@ fn query_and_compare(

let expected_points = expected.get_required::<MyPoint>().unwrap();
let expected_point_data = expected_points
.to_dense::<MyPoint>(&mut resolver)
.to_dense::<MyPoint>(&resolver)
.flatten()
.unwrap();

let expected_colors = expected.get_optional::<MyColor>();
let expected_color_data = expected_colors
.to_sparse::<MyColor>(&mut resolver)
.to_sparse::<MyColor>(&resolver)
.flatten()
.unwrap();

Expand Down

0 comments on commit a4d36cb

Please sign in to comment.