mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
avoid use of format!() to improve performance (#260)
This commit is contained in:
parent
e77588805c
commit
9699cb761a
2 changed files with 34 additions and 29 deletions
|
|
@ -13,6 +13,7 @@ use std::cell::RefCell;
|
|||
|
||||
use crate::{ux::{ListItem, deserialize_app_info}, ctap::FIDO_CRED_DICT, storage};
|
||||
use crate::{VaultMode, SelectedEntry};
|
||||
use crate::utc_now;
|
||||
|
||||
use crate::fido::U2F_APP_DICT;
|
||||
use crate::totp::TotpAlgorithm;
|
||||
|
|
@ -640,6 +641,9 @@ impl<'a> ActionManager<'a> {
|
|||
pw.username = edit_data.content()[1].content.as_str().unwrap().to_string();
|
||||
pw.password = edit_data.content()[2].content.as_str().unwrap().to_string();
|
||||
pw.notes = edit_data.content()[3].content.as_str().unwrap().to_string();
|
||||
// note the edit access, this counts as an access since the password was revealed
|
||||
pw.count += 1;
|
||||
pw.atime = utc_now().timestamp() as u64;
|
||||
storage.update(&choice, key_name, &mut pw)
|
||||
},
|
||||
};
|
||||
|
|
@ -709,11 +713,16 @@ impl<'a> ActionManager<'a> {
|
|||
self.perfentry(&self.pm, PERFMETA_NONE, 1, std::line!());
|
||||
if let Some(data) = key.data {
|
||||
if let Some(pw) = storage::PasswordRecord::try_from(data).ok() {
|
||||
let extra = format!("{}; {}{}",
|
||||
crate::ux::atime_to_str(pw.atime),
|
||||
t!("vault.u2f.appinfo.authcount", xous::LANG),
|
||||
pw.count,
|
||||
let human_time = crate::ux::atime_to_str(pw.atime);
|
||||
// avoid allocations
|
||||
let mut extra = String::with_capacity(
|
||||
human_time.len() +
|
||||
t!("vault.u2f.appinfo.authcount", xous::LANG).len() +
|
||||
11 // space for "count" and "; "
|
||||
);
|
||||
extra.push_str(&human_time);
|
||||
extra.push_str("; ");
|
||||
extra.push_str(&pw.count.to_string());
|
||||
let desc = format!("{}/{}", pw.description, pw.username);
|
||||
let li = ListItem {
|
||||
name: desc,
|
||||
|
|
|
|||
|
|
@ -10,42 +10,38 @@ use chrono::{Utc, DateTime, NaiveDateTime};
|
|||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub(crate) fn atime_to_str(req_atime: u64) -> String {
|
||||
let mut request_str = String::new();
|
||||
let mut request_str = String::with_capacity(
|
||||
// avoid allocations to speed up this routine, it is in the inner loop of rendering lists of passwords
|
||||
t!("vault.u2f.appinfo.last_authtime", xous::LANG).len() +
|
||||
t!("vault.u2f.appinfo.seconds_ago", xous::LANG).len() +
|
||||
16 // space for the actual duration + some slop for translation
|
||||
);
|
||||
if req_atime == 0 {
|
||||
request_str.push_str(&format!("{}{}",
|
||||
t!("vault.u2f.appinfo.last_authtime", xous::LANG),
|
||||
t!("vault.u2f.appinfo.never", xous::LANG)
|
||||
));
|
||||
request_str.push_str(t!("vault.u2f.appinfo.last_authtime", xous::LANG));
|
||||
request_str.push_str(t!("vault.u2f.appinfo.never", xous::LANG));
|
||||
} else {
|
||||
let now = utc_now();
|
||||
let atime = DateTime::<Utc>::from_utc(
|
||||
NaiveDateTime::from_timestamp(req_atime as i64, 0),
|
||||
Utc
|
||||
);
|
||||
// avoid format! macro, it is too slow.
|
||||
if now.signed_duration_since(atime).num_days() > 1 {
|
||||
request_str.push_str(&format!("{}{}{}",
|
||||
t!("vault.u2f.appinfo.last_authtime", xous::LANG),
|
||||
now.signed_duration_since(atime).num_days(),
|
||||
t!("vault.u2f.appinfo.days_ago", xous::LANG),
|
||||
));
|
||||
request_str.push_str(t!("vault.u2f.appinfo.last_authtime", xous::LANG));
|
||||
request_str.push_str(&now.signed_duration_since(atime).num_days().to_string());
|
||||
request_str.push_str(t!("vault.u2f.appinfo.days_ago", xous::LANG));
|
||||
} else if now.signed_duration_since(atime).num_hours() > 1 {
|
||||
request_str.push_str(&format!("{}{}{}",
|
||||
t!("vault.u2f.appinfo.last_authtime", xous::LANG),
|
||||
now.signed_duration_since(atime).num_hours(),
|
||||
t!("vault.u2f.appinfo.hours_ago", xous::LANG),
|
||||
));
|
||||
request_str.push_str(t!("vault.u2f.appinfo.last_authtime", xous::LANG));
|
||||
request_str.push_str(&now.signed_duration_since(atime).num_hours().to_string());
|
||||
request_str.push_str(t!("vault.u2f.appinfo.hours_ago", xous::LANG));
|
||||
} else if now.signed_duration_since(atime).num_minutes() > 1 {
|
||||
request_str.push_str(&format!("{}{}{}",
|
||||
t!("vault.u2f.appinfo.last_authtime", xous::LANG),
|
||||
now.signed_duration_since(atime).num_minutes(),
|
||||
t!("vault.u2f.appinfo.minutes_ago", xous::LANG),
|
||||
));
|
||||
request_str.push_str(t!("vault.u2f.appinfo.last_authtime", xous::LANG));
|
||||
request_str.push_str(&now.signed_duration_since(atime).num_minutes().to_string());
|
||||
request_str.push_str(t!("vault.u2f.appinfo.minutes_ago", xous::LANG));
|
||||
} else {
|
||||
request_str.push_str(&format!("{}{}{}",
|
||||
t!("vault.u2f.appinfo.last_authtime", xous::LANG),
|
||||
now.signed_duration_since(atime).num_seconds(),
|
||||
t!("vault.u2f.appinfo.seconds_ago", xous::LANG),
|
||||
));
|
||||
request_str.push_str(t!("vault.u2f.appinfo.last_authtime", xous::LANG));
|
||||
request_str.push_str(&now.signed_duration_since(atime).num_seconds().to_string());
|
||||
request_str.push_str(t!("vault.u2f.appinfo.seconds_ago", xous::LANG));
|
||||
}
|
||||
}
|
||||
request_str
|
||||
|
|
|
|||
Loading…
Reference in a new issue