forked from 1b-agent/opencadstudio-upstream
refactor(ribbon): make StyleContext borrowed to avoid 8 clones per view
Replace the 8 owned clones in StyleContext construction (4 Vec<String> + 4 String) at ribbon/mod.rs:568 and :1059 with borrowed refs. StyleContext is now StyleContext<'a> with &'a [String]/&'a str (widgets.rs:313), RenderCtx holds &'a StyleContext<'a> (:633), and call sites pass &self.x instead of .clone(). The view-local borrow is valid for the duration of Ribbon::view() and the style dropdown overlay. TDD: RED style_context_tests failed E0308 (owned vs borrowed), GREEN added lifetime and updated 4 type sites + 2 construction sites.
This commit is contained in:
1 parent
fddf505c20
commit
50cb21e4d4
2 files changed
+90
-37
No files matched your search
+18
-18
@@ -566,14 +566,14 @@ impl Ribbon {
|
||||
if let Some(module) = self.modules.get(effective_active) {
|
||||
let groups = module.ribbon_groups();
|
||||
let style_ctx = StyleContext {
|
||||
text_style_names: self.text_style_names.clone(),
|
||||
active_text_style: self.active_text_style.clone(),
|
||||
dim_style_names: self.dim_style_names.clone(),
|
||||
active_dim_style: self.active_dim_style.clone(),
|
||||
mleader_style_names: self.mleader_style_names.clone(),
|
||||
active_mleader_style: self.active_mleader_style.clone(),
|
||||
table_style_names: self.table_style_names.clone(),
|
||||
active_table_style: self.active_table_style.clone(),
|
||||
text_style_names: &self.text_style_names,
|
||||
active_text_style: &self.active_text_style,
|
||||
dim_style_names: &self.dim_style_names,
|
||||
active_dim_style: &self.active_dim_style,
|
||||
mleader_style_names: &self.mleader_style_names,
|
||||
active_mleader_style: &self.active_mleader_style,
|
||||
table_style_names: &self.table_style_names,
|
||||
active_table_style: &self.active_table_style,
|
||||
};
|
||||
|
||||
// Adaptive tool area: panels sit on one row; when they don't all
|
||||
@@ -1057,14 +1057,14 @@ impl Ribbon {
|
||||
let (style_key, manager_cmd) = found?;
|
||||
|
||||
let ctx = StyleContext {
|
||||
text_style_names: self.text_style_names.clone(),
|
||||
active_text_style: self.active_text_style.clone(),
|
||||
dim_style_names: self.dim_style_names.clone(),
|
||||
active_dim_style: self.active_dim_style.clone(),
|
||||
mleader_style_names: self.mleader_style_names.clone(),
|
||||
active_mleader_style: self.active_mleader_style.clone(),
|
||||
table_style_names: self.table_style_names.clone(),
|
||||
active_table_style: self.active_table_style.clone(),
|
||||
text_style_names: &self.text_style_names,
|
||||
active_text_style: &self.active_text_style,
|
||||
dim_style_names: &self.dim_style_names,
|
||||
active_dim_style: &self.active_dim_style,
|
||||
mleader_style_names: &self.mleader_style_names,
|
||||
active_mleader_style: &self.active_mleader_style,
|
||||
table_style_names: &self.table_style_names,
|
||||
active_table_style: &self.active_table_style,
|
||||
};
|
||||
let active = ctx.active_for(style_key).to_string();
|
||||
|
||||
@@ -1298,7 +1298,7 @@ fn render_group<'a>(
|
||||
active_color: AcadColor,
|
||||
active_linetype: &'a str,
|
||||
active_lineweight: LineWeight,
|
||||
style_ctx: &StyleContext,
|
||||
style_ctx: &StyleContext<'_>,
|
||||
) -> Element<'a, Message> {
|
||||
let mut items_row: Vec<Element<Message>> = Vec::new();
|
||||
let mut small_buf: Vec<Element<Message>> = Vec::new();
|
||||
@@ -1419,7 +1419,7 @@ fn collapse_button<'a>(
|
||||
active_color: AcadColor,
|
||||
active_linetype: &'a str,
|
||||
active_lineweight: LineWeight,
|
||||
style_ctx: &StyleContext,
|
||||
style_ctx: &StyleContext<'_>,
|
||||
// When set, this is the TIGHT step (reached once even the all-collapsed row
|
||||
// overflows): the whole panel becomes a single non-running button — the first
|
||||
// tool's icon + a ▾ that opens the tools flyout. Nothing runs directly here.
|
||||
|
||||
Reference in new issue
Block a user