minor optimizations

This commit is contained in:
GyulyVGC 2026-03-16 00:09:55 +01:00
parent c5a390db8e
commit 2457693d4f
6 changed files with 24 additions and 44 deletions

View file

@ -61,11 +61,8 @@ fn page_content<'a>(sniffer: &Sniffer, key: &AddressPortPair) -> Container<'a, M
let data_repr = sniffer.conf.data_repr;
let info_traffic = &sniffer.info_traffic;
let val = info_traffic
.map
.get(key)
.unwrap_or(&InfoAddressPortPair::default())
.clone();
let default_val = InfoAddressPortPair::default();
let val = info_traffic.map.get(key).unwrap_or(&default_val);
let address_to_lookup = get_address_to_lookup(key, val.traffic_direction);
let host_option = sniffer.addresses_resolved.get(&address_to_lookup);
let default_host = Host::default();
@ -126,7 +123,7 @@ fn page_content<'a>(sniffer: &Sniffer, key: &AddressPortPair) -> Container<'a, M
dest_col = dest_col.push(host_info_col);
}
let col_info = col_info(key, &val, data_repr, language);
let col_info = col_info(key, val, data_repr, language);
let content = assemble_widgets(col_info, source_col, dest_col);

View file

@ -102,18 +102,12 @@ fn report<'a>(sniffer: &Sniffer) -> Column<'a, Message, StyleType> {
let mut scroll_report = Column::new().align_x(Alignment::Start);
let start_entry_num = (sniffer.page_number.saturating_sub(1)) * 30 + 1;
let end_entry_num = start_entry_num + search_results.len() - 1;
for report_entry in search_results {
for (key, val) in search_results {
scroll_report = scroll_report.push(
button(row_report_entry(
&report_entry.0,
&report_entry.1,
data_repr,
))
.padding(2)
.on_press(Message::ShowModal(MyModal::ConnectionDetails(
report_entry.0,
)))
.class(ButtonType::Neutral),
button(row_report_entry(key, val, data_repr))
.padding(2)
.on_press(Message::ShowModal(MyModal::ConnectionDetails(*key)))
.class(ButtonType::Neutral),
);
}
if results_number > 0 {

View file

@ -270,7 +270,7 @@ fn input_group_bytes<'a>(
let mut curr_threshold_str = (bytes_notification.threshold.unwrap_or_default()
/ bytes_notification.byte_multiple.multiplier())
.to_string();
curr_threshold_str.push_str(&bytes_notification.byte_multiple.get_char());
curr_threshold_str.push_str(bytes_notification.byte_multiple.get_char());
let input_row = Row::new()
.spacing(5)
.align_y(Alignment::Center)

View file

@ -45,8 +45,6 @@ impl DataRepr {
}
let precision = usize::from(byte_multiple != ByteMultiple::B && n <= 9.95);
format!("{n:.precision$} {}", byte_multiple.pretty_print(self))
.trim()
.to_string()
}
pub fn data_exceeded_translation(&self, language: Language) -> &str {
@ -121,14 +119,14 @@ impl ByteMultiple {
}
}
pub fn get_char(self) -> String {
pub fn get_char(self) -> &'static str {
match self {
Self::B => String::new(),
Self::KB => "K".to_string(),
Self::MB => "M".to_string(),
Self::GB => "G".to_string(),
Self::TB => "T".to_string(),
Self::PB => "P".to_string(),
Self::B => "",
Self::KB => "K",
Self::MB => "M",
Self::GB => "G",
Self::TB => "T",
Self::PB => "P",
}
}

View file

@ -18,7 +18,6 @@ use crate::utils::error_logger::{ErrorLogger, Location};
use crate::utils::formatted_strings::APP_VERSION;
use crate::utils::formatted_strings::get_formatted_timestamp;
use crate::{InfoTraffic, SNIFFNET_LOWERCASE, location};
use std::cmp::min;
use std::collections::{HashMap, HashSet};
use std::net::IpAddr;
@ -171,13 +170,8 @@ fn threshold_hosts(
data_repr,
)
});
let n_entry = min(hosts.len(), 4);
hosts.truncate(4);
hosts
.get(..n_entry)
.unwrap_or_default()
.to_owned()
.into_iter()
.collect()
}
fn threshold_services(
@ -191,13 +185,8 @@ fn threshold_services(
.map(|(s, data_info_fav)| (*s, data_info_fav.data_info))
.collect();
services.sort_by(|(_, a), (_, b)| a.compare(b, SortType::Descending, data_repr));
let n_entry = min(services.len(), 4);
services.truncate(4);
services
.get(..n_entry)
.unwrap_or_default()
.to_owned()
.into_iter()
.collect()
}
fn favorites_last_interval(

View file

@ -13,7 +13,11 @@ use crate::networking::types::info_address_port_pair::InfoAddressPortPair;
/// with their packets, in-bytes, and out-bytes count
pub fn get_searched_entries(
sniffer: &Sniffer,
) -> (Vec<(AddressPortPair, InfoAddressPortPair)>, usize, DataInfo) {
) -> (
Vec<(&AddressPortPair, &InfoAddressPortPair)>,
usize,
DataInfo,
) {
let mut agglomerate = DataInfo::default();
let info_traffic = &sniffer.info_traffic;
let mut all_results: Vec<(&AddressPortPair, &InfoAddressPortPair)> = info_traffic
@ -69,9 +73,7 @@ pub fn get_searched_entries(
all_results
.get((sniffer.page_number.saturating_sub(1)) * 30..upper_bound)
.unwrap_or_default()
.iter()
.map(|&(key, val)| (key.to_owned(), val.to_owned()))
.collect(),
.to_vec(),
all_results.len(),
agglomerate,
)