Skip to content

Commit

Permalink
🐎 Reduce memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Oct 30, 2024
1 parent 72471b5 commit b34e2ed
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions cli/src/chunk/acl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bitflags::bitflags;
use itertools::Itertools;
use pna::ChunkType;
use std::{
error::Error,
Expand Down Expand Up @@ -177,28 +178,22 @@ const PERMISSION_NAME_MAP: &[(Permission, &[&str])] = &[
impl Display for Ace {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut flags = Vec::new();
for (f, names) in FLAG_NAME_MAP {
if self.flags.contains(*f) {
flags.push(names[0]);
}
}

let mut permission_list = Vec::new();
for (f, names) in PERMISSION_NAME_MAP {
if self.permission.contains(*f) {
permission_list.push(names[0]);
}
}

write!(
f,
"{}:{}:{}:{}:{}",
self.platform,
flags.join(","),
FLAG_NAME_MAP
.iter()
.filter(|(f, _)| self.flags.contains(*f))
.map(|(_, names)| names[0])
.join(","),
self.owner_type,
if self.allow { "allow" } else { "deny" },
permission_list.join(","),
PERMISSION_NAME_MAP
.iter()
.filter(|(f, _)| self.permission.contains(*f))
.map(|(_, names)| names[0])
.join(","),
)
}
}
Expand Down

0 comments on commit b34e2ed

Please sign in to comment.