1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-16 22:08:47 +00:00

perf(core): optimize AddressDetails::xpubs layout

[no changelog]
This commit is contained in:
Roman Zeyde 2025-04-22 21:07:29 +03:00 committed by Roman Zeyde
parent 6a0a02e17c
commit bd9d303310
9 changed files with 26 additions and 33 deletions

View File

@ -2,6 +2,7 @@ use heapless::Vec;
use crate::{ use crate::{
error::Error, error::Error,
micropython::buffer::StrBuffer,
strutil::TString, strutil::TString,
translations::TR, translations::TR,
ui::{ ui::{
@ -22,7 +23,7 @@ pub struct AddressDetails {
qr_code: Frame<Qr>, qr_code: Frame<Qr>,
details: Frame<Paragraphs<ParagraphVecShort<'static>>>, details: Frame<Paragraphs<ParagraphVecShort<'static>>>,
xpub_view: Frame<Paragraphs<Paragraph<'static>>>, xpub_view: Frame<Paragraphs<Paragraph<'static>>>,
xpubs: Vec<(TString<'static>, TString<'static>), MAX_XPUBS>, xpubs: Vec<(StrBuffer, StrBuffer), MAX_XPUBS>,
xpub_page_count: Vec<u8, MAX_XPUBS>, xpub_page_count: Vec<u8, MAX_XPUBS>,
current_page: usize, current_page: usize,
} }
@ -82,11 +83,7 @@ impl AddressDetails {
Ok(result) Ok(result)
} }
pub fn add_xpub( pub fn add_xpub(&mut self, title: StrBuffer, xpub: StrBuffer) -> Result<(), Error> {
&mut self,
title: TString<'static>,
xpub: TString<'static>,
) -> Result<(), Error> {
self.xpubs self.xpubs
.push((title, xpub)) .push((title, xpub))
.map_err(|_| Error::OutOfRange) .map_err(|_| Error::OutOfRange)
@ -97,7 +94,8 @@ impl AddressDetails {
// case the parent component that handles paging always requests complete // case the parent component that handles paging always requests complete
// repaint after page change so we can use a dummy context here. // repaint after page change so we can use a dummy context here.
let mut dummy_ctx = EventCtx::new(); 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| { self.xpub_view.update_content(&mut dummy_ctx, |p| {
p.update(self.xpubs[i].1); p.update(self.xpubs[i].1);
p.change_page(page); p.change_page(page);

View File

@ -1,4 +1,4 @@
#[cfg(feature = "translations")] #[cfg(all(feature = "micropython", feature = "translations"))]
mod address_details; mod address_details;
pub mod bl_confirm; pub mod bl_confirm;
mod button; mod button;
@ -29,7 +29,7 @@ mod simple_page;
mod swipe; mod swipe;
mod welcome_screen; mod welcome_screen;
#[cfg(feature = "translations")] #[cfg(all(feature = "micropython", feature = "translations"))]
pub use address_details::AddressDetails; pub use address_details::AddressDetails;
pub use button::{ pub use button::{
Button, ButtonContent, ButtonMsg, ButtonStyle, ButtonStyleSheet, CancelConfirmMsg, Button, ButtonContent, ButtonMsg, ButtonStyle, ButtonStyleSheet, CancelConfirmMsg,

View File

@ -3,7 +3,7 @@ use core::cmp::Ordering;
use crate::{ use crate::{
error::{value_error, Error}, error::{value_error, Error},
io::BinaryData, 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, strutil::TString,
translations::TR, translations::TR,
ui::{ ui::{
@ -754,7 +754,7 @@ impl FirmwareUI for UIBolt {
)?; )?;
for i in IterBuf::new().try_iterate(xpubs)? { 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)?; ad.add_xpub(xtitle, text)?;
} }

View File

@ -2,6 +2,7 @@ use heapless::Vec;
use crate::{ use crate::{
error::Error, error::Error,
micropython::buffer::StrBuffer,
strutil::TString, strutil::TString,
translations::TR, translations::TR,
ui::{ ui::{
@ -25,7 +26,7 @@ pub struct AddressDetails {
qr_code: Qr, qr_code: Qr,
details_view: Paragraphs<ParagraphVecShort<'static>>, details_view: Paragraphs<ParagraphVecShort<'static>>,
xpub_view: Frame<Paragraphs<Paragraph<'static>>>, xpub_view: Frame<Paragraphs<Paragraph<'static>>>,
xpubs: Vec<(TString<'static>, TString<'static>), MAX_XPUBS>, xpubs: Vec<(StrBuffer, StrBuffer), MAX_XPUBS>,
current_page: usize, current_page: usize,
current_subpage: usize, current_subpage: usize,
area: Rect, area: Rect,
@ -77,11 +78,7 @@ impl AddressDetails {
Ok(result) Ok(result)
} }
pub fn add_xpub( pub fn add_xpub(&mut self, title: StrBuffer, xpub: StrBuffer) -> Result<(), Error> {
&mut self,
title: TString<'static>,
xpub: TString<'static>,
) -> Result<(), Error> {
self.xpubs self.xpubs
.push((title, xpub)) .push((title, xpub))
.map_err(|_| Error::OutOfRange) .map_err(|_| Error::OutOfRange)
@ -156,7 +153,7 @@ impl AddressDetails {
fn fill_xpub_page(&mut self, ctx: &mut EventCtx) { fn fill_xpub_page(&mut self, ctx: &mut EventCtx) {
let i = self.current_page - 2; 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| { self.xpub_view.update_content(ctx, |p| {
p.update(self.xpubs[i].1); p.update(self.xpubs[i].1);
p.change_page(0) p.change_page(0)

View File

@ -25,7 +25,7 @@ pub use loader::{Loader, LoaderMsg, LoaderStyle, LoaderStyleSheet, ProgressLoade
pub use result::ResultScreen; pub use result::ResultScreen;
pub use welcome_screen::WelcomeScreen; pub use welcome_screen::WelcomeScreen;
#[cfg(feature = "translations")] #[cfg(all(feature = "micropython", feature = "translations"))]
mod address_details; mod address_details;
mod changing_text; mod changing_text;
#[cfg(feature = "translations")] #[cfg(feature = "translations")]
@ -44,7 +44,7 @@ mod share_words;
mod show_more; mod show_more;
mod title; mod title;
#[cfg(feature = "translations")] #[cfg(all(feature = "micropython", feature = "translations"))]
pub use address_details::AddressDetails; pub use address_details::AddressDetails;
pub use changing_text::ChangingTextLine; pub use changing_text::ChangingTextLine;

View File

@ -4,7 +4,7 @@ use crate::{
error::Error, error::Error,
io::BinaryData, io::BinaryData,
maybe_trace::MaybeTrace, 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, strutil::TString,
translations::TR, translations::TR,
ui::{ ui::{
@ -933,7 +933,7 @@ impl FirmwareUI for UICaesar {
let mut ad = AddressDetails::new(address, case_sensitive, account, path)?; let mut ad = AddressDetails::new(address, case_sensitive, account, path)?;
for i in IterBuf::new().try_iterate(xpubs)? { 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)?; ad.add_xpub(xtitle, text)?;
} }

View File

@ -2,6 +2,7 @@ use heapless::Vec;
use crate::{ use crate::{
error::Error, error::Error,
micropython::buffer::StrBuffer,
strutil::TString, strutil::TString,
translations::TR, translations::TR,
ui::{ ui::{
@ -25,7 +26,7 @@ const MAX_XPUBS: usize = 16;
pub struct AddressDetails { pub struct AddressDetails {
details: Frame<Paragraphs<ParagraphVecShort<'static>>>, details: Frame<Paragraphs<ParagraphVecShort<'static>>>,
xpub_view: Frame<Paragraphs<Paragraph<'static>>>, xpub_view: Frame<Paragraphs<Paragraph<'static>>>,
xpubs: Vec<(TString<'static>, TString<'static>), MAX_XPUBS>, xpubs: Vec<(StrBuffer, StrBuffer), MAX_XPUBS>,
xpub_page_count: Vec<u8, MAX_XPUBS>, xpub_page_count: Vec<u8, MAX_XPUBS>,
current_page: u16, current_page: u16,
} }
@ -75,11 +76,7 @@ impl AddressDetails {
Ok(result) Ok(result)
} }
pub fn add_xpub( pub fn add_xpub(&mut self, title: StrBuffer, xpub: StrBuffer) -> Result<(), Error> {
&mut self,
title: TString<'static>,
xpub: TString<'static>,
) -> Result<(), Error> {
self.xpubs self.xpubs
.push((title, xpub)) .push((title, xpub))
.map_err(|_| Error::OutOfRange) .map_err(|_| Error::OutOfRange)
@ -90,7 +87,8 @@ impl AddressDetails {
// case the parent component that handles paging always requests complete // case the parent component that handles paging always requests complete
// repaint after page change so we can use a dummy context here. // repaint after page change so we can use a dummy context here.
let mut dummy_ctx = EventCtx::new(); 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| { self.xpub_view.update_content(&mut dummy_ctx, |_ctx, p| {
p.update(self.xpubs[i].1); p.update(self.xpubs[i].1);
p.change_page(page); p.change_page(page);

View File

@ -1,4 +1,4 @@
#[cfg(feature = "translations")] #[cfg(all(feature = "micropython", feature = "translations"))]
mod address_details; mod address_details;
#[cfg(feature = "ui_overlay")] #[cfg(feature = "ui_overlay")]
mod binary_selection; mod binary_selection;
@ -40,7 +40,7 @@ mod tap_to_confirm;
mod updatable_more_info; mod updatable_more_info;
mod welcome_screen; mod welcome_screen;
#[cfg(feature = "translations")] #[cfg(all(feature = "micropython", feature = "translations"))]
pub use address_details::AddressDetails; pub use address_details::AddressDetails;
#[cfg(feature = "ui_overlay")] #[cfg(feature = "ui_overlay")]
pub use binary_selection::{BinarySelection, BinarySelectionMsg}; pub use binary_selection::{BinarySelection, BinarySelectionMsg};

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
error, error,
micropython::{iter::IterBuf, obj::Obj, util}, micropython::{buffer::StrBuffer, iter::IterBuf, obj::Obj, util},
strutil::TString, strutil::TString,
translations::TR, translations::TR,
ui::{ ui::{
@ -168,7 +168,7 @@ pub fn new_get_address(
// AccountInfo // AccountInfo
let mut ad = AddressDetails::new(TR::address_details__account_info.into(), account, path)?; let mut ad = AddressDetails::new(TR::address_details__account_info.into(), account, path)?;
for i in IterBuf::new().try_iterate(xpubs)? { 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)?; ad.add_xpub(xtitle, text)?;
} }
let content_account = ad.map(|_| Some(FlowMsg::Cancelled)); let content_account = ad.map(|_| Some(FlowMsg::Cancelled));