perf: don't clone bytes via a more specialized function
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -135,6 +135,30 @@ pub fn show_with_nickname(
|
|||||||
Ok(ui_element(ui, &get_display_name(&profile)))
|
Ok(ui_element(ui, &get_display_name(&profile)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_with_selected_pfp(
|
||||||
|
app: &mut Damus,
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
ui_element: fn(ui: &mut egui::Ui, pfp: ProfilePic) -> egui::Response,
|
||||||
|
) -> Option<egui::Response> {
|
||||||
|
let selected_account = app.account_manager.get_selected_account();
|
||||||
|
if let Some(selected_account) = selected_account {
|
||||||
|
if let Ok(txn) = Transaction::new(&app.ndb) {
|
||||||
|
let profile = app
|
||||||
|
.ndb
|
||||||
|
.get_profile_by_pubkey(&txn, selected_account.pubkey.bytes());
|
||||||
|
|
||||||
|
if let Ok(profile) = profile {
|
||||||
|
return Some(ui_element(
|
||||||
|
ui,
|
||||||
|
ProfilePic::new(&mut app.img_cache, get_profile_url(&profile)),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn show_with_pfp(
|
pub fn show_with_pfp(
|
||||||
app: &mut Damus,
|
app: &mut Damus,
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
|
|||||||
@@ -71,18 +71,7 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn pfp_button(&mut self, ui: &mut egui::Ui) -> egui::Response {
|
fn pfp_button(&mut self, ui: &mut egui::Ui) -> egui::Response {
|
||||||
let selected_account = self.app.account_manager.get_selected_account();
|
profile_preview_controller::show_with_selected_pfp(self.app, ui, show_pfp());
|
||||||
if let Some(selected_account) = selected_account {
|
|
||||||
if let Some(response) = profile_preview_controller::show_with_pfp(
|
|
||||||
self.app,
|
|
||||||
ui,
|
|
||||||
&selected_account.pubkey.bytes().clone(),
|
|
||||||
show_pfp(),
|
|
||||||
) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
add_button_to_ui(ui, no_account_pfp())
|
add_button_to_ui(ui, no_account_pfp())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user