Skip to content

Commit

Permalink
aya: don't allocate static strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Jul 10, 2023
1 parent c89c485 commit 27120b3
Show file tree
Hide file tree
Showing 46 changed files with 227 additions and 224 deletions.
42 changes: 21 additions & 21 deletions aya-bpf-macros/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Map {
}

pub fn expand(&self) -> Result<TokenStream> {
let section_name = "maps".to_string();
let section_name = "maps";
let name = &self.name;
let item = &self.item;
Ok(quote! {
Expand Down Expand Up @@ -148,10 +148,10 @@ impl SockOps {
}

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("sockops/{name}")
let section_name: std::borrow::Cow<'_, _> = if let Some(name) = &self.name {
format!("sockops/{name}").into()
} else {
"sockops".to_owned()
"sockops".into()
};
let fn_vis = &self.item.vis;
let fn_name = &self.item.sig.ident;
Expand Down Expand Up @@ -256,10 +256,10 @@ impl SchedClassifier {
}

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("classifier/{name}")
let section_name: std::borrow::Cow<'_, _> = if let Some(name) = &self.name {
format!("classifier/{name}").into()
} else {
"classifier".to_owned()
"classifier".into()
};
let fn_vis = &self.item.vis;
let fn_name = &self.item.sig.ident;
Expand Down Expand Up @@ -452,16 +452,16 @@ impl CgroupSock {
}

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
let section_name: std::borrow::Cow<'_, _> = if let Some(name) = &self.name {
if let Some(attach_type) = &self.attach_type {
format!("cgroup/{attach_type}/{name}")
format!("cgroup/{attach_type}/{name}").into()
} else {
format!("cgroup/sock/{name}")
format!("cgroup/sock/{name}").into()
}
} else if let Some(attach_type) = &self.attach_type {
format!("cgroup/{attach_type}")
format!("cgroup/{attach_type}").into()
} else {
"cgroup/sock".to_string()
"cgroup/sock".into()
};
let fn_vis = &self.item.vis;
let fn_name = &self.item.sig.ident;
Expand Down Expand Up @@ -761,10 +761,10 @@ impl SocketFilter {
}

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("socket/{name}")
let section_name: std::borrow::Cow<'_, _> = if let Some(name) = &self.name {
format!("socket/{name}").into()
} else {
"socket".to_owned()
"socket".into()
};
let fn_vis = &self.item.vis;
let fn_name = &self.item.sig.ident;
Expand Down Expand Up @@ -854,10 +854,10 @@ impl SkLookup {
}

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("sk_lookup/{name}")
let section_name: std::borrow::Cow<'_, _> = if let Some(name) = &self.name {
format!("sk_lookup/{name}").into()
} else {
"sk_lookup".to_owned()
"sk_lookup".into()
};
let fn_vis = &self.item.vis;
let fn_name = &self.item.sig.ident;
Expand Down Expand Up @@ -887,10 +887,10 @@ impl CgroupDevice {
}

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("cgroup/dev/{name}")
let section_name: std::borrow::Cow<'_, _> = if let Some(name) = &self.name {
format!("cgroup/dev/{name}").into()
} else {
("cgroup/dev").to_owned()
"cgroup/dev".into()
};
let fn_vis = &self.item.vis;
let fn_name = &self.item.sig.ident;
Expand Down
Loading

0 comments on commit 27120b3

Please sign in to comment.