From bd9d3033101ba6b600f4be96da3d79cbd06049c7 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 22 Apr 2025 21:07:29 +0300 Subject: [PATCH] perf(core): optimize `AddressDetails::xpubs` layout [no changelog] --- .../src/ui/layout_bolt/component/address_details.rs | 12 +++++------- core/embed/rust/src/ui/layout_bolt/component/mod.rs | 4 ++-- core/embed/rust/src/ui/layout_bolt/ui_firmware.rs | 4 ++-- .../ui/layout_caesar/component/address_details.rs | 11 ++++------- .../embed/rust/src/ui/layout_caesar/component/mod.rs | 4 ++-- core/embed/rust/src/ui/layout_caesar/ui_firmware.rs | 4 ++-- .../ui/layout_delizia/component/address_details.rs | 12 +++++------- .../rust/src/ui/layout_delizia/component/mod.rs | 4 ++-- .../rust/src/ui/layout_delizia/flow/get_address.rs | 4 ++-- 9 files changed, 26 insertions(+), 33 deletions(-) diff --git a/core/embed/rust/src/ui/layout_bolt/component/address_details.rs b/core/embed/rust/src/ui/layout_bolt/component/address_details.rs index 38cff4ac9c..b80d24f8f5 100644 --- a/core/embed/rust/src/ui/layout_bolt/component/address_details.rs +++ b/core/embed/rust/src/ui/layout_bolt/component/address_details.rs @@ -2,6 +2,7 @@ use heapless::Vec; use crate::{ error::Error, + micropython::buffer::StrBuffer, strutil::TString, translations::TR, ui::{ @@ -22,7 +23,7 @@ pub struct AddressDetails { qr_code: Frame, details: Frame>>, xpub_view: Frame>>, - xpubs: Vec<(TString<'static>, TString<'static>), MAX_XPUBS>, + xpubs: Vec<(StrBuffer, StrBuffer), MAX_XPUBS>, xpub_page_count: Vec, current_page: usize, } @@ -82,11 +83,7 @@ impl AddressDetails { Ok(result) } - pub fn add_xpub( - &mut self, - title: TString<'static>, - xpub: TString<'static>, - ) -> Result<(), Error> { + pub fn add_xpub(&mut self, title: StrBuffer, xpub: StrBuffer) -> Result<(), Error> { self.xpubs .push((title, xpub)) .map_err(|_| Error::OutOfRange) @@ -97,7 +94,8 @@ impl AddressDetails { // case the parent component that handles paging always requests complete // repaint after page change so we can use a dummy context here. let mut dummy_ctx = EventCtx::new(); - self.xpub_view.update_title(&mut dummy_ctx, self.xpubs[i].0); + self.xpub_view + .update_title(&mut dummy_ctx, self.xpubs[i].0.into()); self.xpub_view.update_content(&mut dummy_ctx, |p| { p.update(self.xpubs[i].1); p.change_page(page); diff --git a/core/embed/rust/src/ui/layout_bolt/component/mod.rs b/core/embed/rust/src/ui/layout_bolt/component/mod.rs index a3caaf2152..425ac081c6 100644 --- a/core/embed/rust/src/ui/layout_bolt/component/mod.rs +++ b/core/embed/rust/src/ui/layout_bolt/component/mod.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "translations")] +#[cfg(all(feature = "micropython", feature = "translations"))] mod address_details; pub mod bl_confirm; mod button; @@ -29,7 +29,7 @@ mod simple_page; mod swipe; mod welcome_screen; -#[cfg(feature = "translations")] +#[cfg(all(feature = "micropython", feature = "translations"))] pub use address_details::AddressDetails; pub use button::{ Button, ButtonContent, ButtonMsg, ButtonStyle, ButtonStyleSheet, CancelConfirmMsg, diff --git a/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs b/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs index 8512c60900..b8db5feb1b 100644 --- a/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs @@ -3,7 +3,7 @@ use core::cmp::Ordering; use crate::{ error::{value_error, Error}, io::BinaryData, - micropython::{gc::Gc, iter::IterBuf, list::List, obj::Obj, util}, + micropython::{buffer::StrBuffer, gc::Gc, iter::IterBuf, list::List, obj::Obj, util}, strutil::TString, translations::TR, ui::{ @@ -754,7 +754,7 @@ impl FirmwareUI for UIBolt { )?; for i in IterBuf::new().try_iterate(xpubs)? { - let [xtitle, text]: [TString; 2] = util::iter_into_array(i)?; + let [xtitle, text]: [StrBuffer; 2] = util::iter_into_array(i)?; ad.add_xpub(xtitle, text)?; } diff --git a/core/embed/rust/src/ui/layout_caesar/component/address_details.rs b/core/embed/rust/src/ui/layout_caesar/component/address_details.rs index 6fca107c2f..5252fa8996 100644 --- a/core/embed/rust/src/ui/layout_caesar/component/address_details.rs +++ b/core/embed/rust/src/ui/layout_caesar/component/address_details.rs @@ -2,6 +2,7 @@ use heapless::Vec; use crate::{ error::Error, + micropython::buffer::StrBuffer, strutil::TString, translations::TR, ui::{ @@ -25,7 +26,7 @@ pub struct AddressDetails { qr_code: Qr, details_view: Paragraphs>, xpub_view: Frame>>, - xpubs: Vec<(TString<'static>, TString<'static>), MAX_XPUBS>, + xpubs: Vec<(StrBuffer, StrBuffer), MAX_XPUBS>, current_page: usize, current_subpage: usize, area: Rect, @@ -77,11 +78,7 @@ impl AddressDetails { Ok(result) } - pub fn add_xpub( - &mut self, - title: TString<'static>, - xpub: TString<'static>, - ) -> Result<(), Error> { + pub fn add_xpub(&mut self, title: StrBuffer, xpub: StrBuffer) -> Result<(), Error> { self.xpubs .push((title, xpub)) .map_err(|_| Error::OutOfRange) @@ -156,7 +153,7 @@ impl AddressDetails { fn fill_xpub_page(&mut self, ctx: &mut EventCtx) { let i = self.current_page - 2; - self.xpub_view.update_title(ctx, self.xpubs[i].0); + self.xpub_view.update_title(ctx, self.xpubs[i].0.into()); self.xpub_view.update_content(ctx, |p| { p.update(self.xpubs[i].1); p.change_page(0) diff --git a/core/embed/rust/src/ui/layout_caesar/component/mod.rs b/core/embed/rust/src/ui/layout_caesar/component/mod.rs index 088703a305..35946ccab1 100644 --- a/core/embed/rust/src/ui/layout_caesar/component/mod.rs +++ b/core/embed/rust/src/ui/layout_caesar/component/mod.rs @@ -25,7 +25,7 @@ pub use loader::{Loader, LoaderMsg, LoaderStyle, LoaderStyleSheet, ProgressLoade pub use result::ResultScreen; pub use welcome_screen::WelcomeScreen; -#[cfg(feature = "translations")] +#[cfg(all(feature = "micropython", feature = "translations"))] mod address_details; mod changing_text; #[cfg(feature = "translations")] @@ -44,7 +44,7 @@ mod share_words; mod show_more; mod title; -#[cfg(feature = "translations")] +#[cfg(all(feature = "micropython", feature = "translations"))] pub use address_details::AddressDetails; pub use changing_text::ChangingTextLine; diff --git a/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs b/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs index b4c4f1ac00..e843426697 100644 --- a/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs @@ -4,7 +4,7 @@ use crate::{ error::Error, io::BinaryData, maybe_trace::MaybeTrace, - micropython::{gc::Gc, iter::IterBuf, list::List, obj::Obj, util}, + micropython::{buffer::StrBuffer, gc::Gc, iter::IterBuf, list::List, obj::Obj, util}, strutil::TString, translations::TR, ui::{ @@ -933,7 +933,7 @@ impl FirmwareUI for UICaesar { let mut ad = AddressDetails::new(address, case_sensitive, account, path)?; for i in IterBuf::new().try_iterate(xpubs)? { - let [xtitle, text]: [TString; 2] = util::iter_into_array(i)?; + let [xtitle, text]: [StrBuffer; 2] = util::iter_into_array(i)?; ad.add_xpub(xtitle, text)?; } diff --git a/core/embed/rust/src/ui/layout_delizia/component/address_details.rs b/core/embed/rust/src/ui/layout_delizia/component/address_details.rs index 9e625428dd..62c213a34b 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/address_details.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/address_details.rs @@ -2,6 +2,7 @@ use heapless::Vec; use crate::{ error::Error, + micropython::buffer::StrBuffer, strutil::TString, translations::TR, ui::{ @@ -25,7 +26,7 @@ const MAX_XPUBS: usize = 16; pub struct AddressDetails { details: Frame>>, xpub_view: Frame>>, - xpubs: Vec<(TString<'static>, TString<'static>), MAX_XPUBS>, + xpubs: Vec<(StrBuffer, StrBuffer), MAX_XPUBS>, xpub_page_count: Vec, current_page: u16, } @@ -75,11 +76,7 @@ impl AddressDetails { Ok(result) } - pub fn add_xpub( - &mut self, - title: TString<'static>, - xpub: TString<'static>, - ) -> Result<(), Error> { + pub fn add_xpub(&mut self, title: StrBuffer, xpub: StrBuffer) -> Result<(), Error> { self.xpubs .push((title, xpub)) .map_err(|_| Error::OutOfRange) @@ -90,7 +87,8 @@ impl AddressDetails { // case the parent component that handles paging always requests complete // repaint after page change so we can use a dummy context here. let mut dummy_ctx = EventCtx::new(); - self.xpub_view.update_title(&mut dummy_ctx, self.xpubs[i].0); + self.xpub_view + .update_title(&mut dummy_ctx, self.xpubs[i].0.into()); self.xpub_view.update_content(&mut dummy_ctx, |_ctx, p| { p.update(self.xpubs[i].1); p.change_page(page); diff --git a/core/embed/rust/src/ui/layout_delizia/component/mod.rs b/core/embed/rust/src/ui/layout_delizia/component/mod.rs index 6f74325f2c..be3235db52 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/mod.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/mod.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "translations")] +#[cfg(all(feature = "micropython", feature = "translations"))] mod address_details; #[cfg(feature = "ui_overlay")] mod binary_selection; @@ -40,7 +40,7 @@ mod tap_to_confirm; mod updatable_more_info; mod welcome_screen; -#[cfg(feature = "translations")] +#[cfg(all(feature = "micropython", feature = "translations"))] pub use address_details::AddressDetails; #[cfg(feature = "ui_overlay")] pub use binary_selection::{BinarySelection, BinarySelectionMsg}; diff --git a/core/embed/rust/src/ui/layout_delizia/flow/get_address.rs b/core/embed/rust/src/ui/layout_delizia/flow/get_address.rs index db03d2541f..cf248714b1 100644 --- a/core/embed/rust/src/ui/layout_delizia/flow/get_address.rs +++ b/core/embed/rust/src/ui/layout_delizia/flow/get_address.rs @@ -1,6 +1,6 @@ use crate::{ error, - micropython::{iter::IterBuf, obj::Obj, util}, + micropython::{buffer::StrBuffer, iter::IterBuf, obj::Obj, util}, strutil::TString, translations::TR, ui::{ @@ -168,7 +168,7 @@ pub fn new_get_address( // AccountInfo let mut ad = AddressDetails::new(TR::address_details__account_info.into(), account, path)?; for i in IterBuf::new().try_iterate(xpubs)? { - let [xtitle, text]: [TString; 2] = util::iter_into_array(i)?; + let [xtitle, text]: [StrBuffer; 2] = util::iter_into_array(i)?; ad.add_xpub(xtitle, text)?; } let content_account = ad.map(|_| Some(FlowMsg::Cancelled));