Skip to content

Commit

Permalink
Wrap AnyView.cached_style in an Rc to make clone efficient
Browse files Browse the repository at this point in the history
Byte size before was 672, now is 56
  • Loading branch information
mgsloan committed Jan 4, 2025
1 parent 8c253af commit faa2d4f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions crates/gpui/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
use anyhow::{Context, Result};
use refineable::Refineable;
use std::mem;
use std::rc::Rc;
use std::{
any::{type_name, TypeId},
fmt,
Expand Down Expand Up @@ -227,15 +228,15 @@ impl<V> Eq for WeakView<V> {}
pub struct AnyView {
model: AnyModel,
render: fn(&AnyView, &mut WindowContext) -> AnyElement,
cached_style: Option<StyleRefinement>,
cached_style: Rc<Option<StyleRefinement>>,
}

impl AnyView {
/// Indicate that this view should be cached when using it as an element.
/// When using this method, the view's previous layout and paint will be recycled from the previous frame if [ViewContext::notify] has not been called since it was rendered.
/// The one exception is when [WindowContext::refresh] is called, in which case caching is ignored.
pub fn cached(mut self, style: StyleRefinement) -> Self {
self.cached_style = Some(style);
self.cached_style = Some(style).into();
self
}

Expand Down Expand Up @@ -276,7 +277,7 @@ impl<V: Render> From<View<V>> for AnyView {
AnyView {
model: value.model.into_any(),
render: any_view::render::<V>,
cached_style: None,
cached_style: None.into(),
}
}
}
Expand Down Expand Up @@ -432,7 +433,7 @@ impl AnyWeakView {
Some(AnyView {
model,
render: self.render,
cached_style: None,
cached_style: None.into(),
})
}
}
Expand Down

0 comments on commit faa2d4f

Please sign in to comment.