Skip to content

Commit

Permalink
remove useless .collect
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Jan 19, 2025
1 parent 470e083 commit ec0ca81
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 52 deletions.
14 changes: 6 additions & 8 deletions oryx-tui/src/ebpf/firewall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ pub fn update_ipv4_blocklist(
} else {
let not_null_ports = blocked_ports
.into_iter()
.filter(|p| (*p != 0 && *p != port))
.collect::<Vec<u16>>();
.filter(|p| (*p != 0 && *p != port));

let mut blocked_ports = [0; MAX_RULES_PORT];

for (idx, p) in not_null_ports.iter().enumerate() {
blocked_ports[idx] = *p;
for (idx, p) in not_null_ports.enumerate() {
blocked_ports[idx] = p;
}

if blocked_ports.iter().all(|&port| port == 0) {
Expand Down Expand Up @@ -98,13 +97,12 @@ pub fn update_ipv6_blocklist(
} else {
let not_null_ports = blocked_ports
.into_iter()
.filter(|p| (*p != 0 && *p != port))
.collect::<Vec<u16>>();
.filter(|p| (*p != 0 && *p != port));

let mut blocked_ports = [0; MAX_RULES_PORT];

for (idx, p) in not_null_ports.iter().enumerate() {
blocked_ports[idx] = *p;
for (idx, p) in not_null_ports.enumerate() {
blocked_ports[idx] = p;
}

if blocked_ports.iter().all(|&port| port == 0) {
Expand Down
11 changes: 3 additions & 8 deletions oryx-tui/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,9 @@ impl Help {

self.block_height = block.height as usize;
let widths = [Constraint::Length(20), Constraint::Fill(1)];
let rows: Vec<Row> = self
.keys
.iter()
.map(|key| {
Row::new(vec![key.0.to_owned(), key.1.into()])
.style(Style::default().fg(Color::White))
})
.collect();
let rows = self.keys.iter().map(|key| {
Row::new(vec![key.0.to_owned(), key.1.into()]).style(Style::default().fg(Color::White))
});
let rows_len = self.keys.len().saturating_sub(self.block_height - 6);

let table = Table::new(rows, widths).block(
Expand Down
62 changes: 29 additions & 33 deletions oryx-tui/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,40 +168,36 @@ impl Interface {
Constraint::Fill(1),
];

let interfaces: Vec<Row> = self
.interfaces
.iter()
.map(|interface| {
let addr = {
match interface
.addresses
.iter()
.find(|a| matches!(a, IpAddr::V4(_) | IpAddr::V6(_)))
{
Some(a) => a.to_string(),
None => String::new(),
}
};

let state = if interface.is_up { "Up" } else { "Down" };

Row::new(if self.selected_interface.name == interface.name {
vec![
Line::from(" "),
Line::from(interface.name.clone()),
Line::from(state.to_string()).centered(),
Line::from(addr.clone()),
]
} else {
vec![
Line::from(""),
Line::from(interface.name.clone()),
Line::from(state.to_string()).centered(),
Line::from(addr.clone()),
]
})
let interfaces = self.interfaces.iter().map(|interface| {
let addr = {
match interface
.addresses
.iter()
.find(|a| matches!(a, IpAddr::V4(_) | IpAddr::V6(_)))
{
Some(a) => a.to_string(),
None => String::new(),
}
};

let state = if interface.is_up { "Up" } else { "Down" };

Row::new(if self.selected_interface.name == interface.name {
vec![
Line::from(" "),
Line::from(interface.name.clone()),
Line::from(state.to_string()).centered(),
Line::from(addr.clone()),
]
} else {
vec![
Line::from(""),
Line::from(interface.name.clone()),
Line::from(state.to_string()).centered(),
Line::from(addr.clone()),
]
})
.collect();
});

let table = Table::new(interfaces, widths)
.header(
Expand Down
4 changes: 1 addition & 3 deletions oryx-tui/src/section/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ impl Metrics {
pub fn render(&mut self, frame: &mut Frame, block: Rect) {
self.window_height = block.height.saturating_sub(4) as usize / 8;

let constraints: Vec<Constraint> = (0..self.window_height)
.map(|_| Constraint::Length(8))
.collect();
let constraints = (0..self.window_height).map(|_| Constraint::Length(8));

let chunks = Layout::default()
.direction(Direction::Vertical)
Expand Down

0 comments on commit ec0ca81

Please sign in to comment.