From 1f2205d75ccbb2d2c53e4484317f7425755b5d8b Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Thu, 6 Feb 2025 01:37:46 -0700 Subject: [PATCH] Wrap AnyView.cached_style in an Rc to make the struct much smaller (#24363) Byte size before was 672, now is 56. The `cached` method is only used in two places, so this was a lot of extra bytes being shuffled around for every `AnyView` not using this. Release Notes: - N/A --- crates/gpui/src/view.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/view.rs b/crates/gpui/src/view.rs index 86d6def7cc..c6483ba6ae 100644 --- a/crates/gpui/src/view.rs +++ b/crates/gpui/src/view.rs @@ -8,6 +8,7 @@ use anyhow::Result; use collections::FxHashSet; use refineable::Refineable; use std::mem; +use std::rc::Rc; use std::{any::TypeId, fmt, ops::Range}; struct AnyViewState { @@ -73,7 +74,7 @@ impl Element for Entity { pub struct AnyView { entity: AnyEntity, render: fn(&AnyView, &mut Window, &mut App) -> AnyElement, - cached_style: Option, + cached_style: Option>, } impl From> for AnyView { @@ -91,7 +92,7 @@ impl AnyView { /// When using this method, the view's previous layout and paint will be recycled from the previous frame if [Context::notify] has not been called since it was rendered. /// The one exception is when [Window::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 }