Replace some String usages with SmolStr in completions

This commit is contained in:
Lukas Wirth 2021-11-05 12:30:39 +01:00
parent 439a8194b0
commit 2f5afba9f8
18 changed files with 99 additions and 111 deletions

View file

@ -66,24 +66,21 @@ impl CfgOptions {
}
}
pub fn get_cfg_keys(&self) -> Vec<&SmolStr> {
self.enabled
.iter()
.map(|x| match x {
CfgAtom::Flag(key) => key,
CfgAtom::KeyValue { key, .. } => key,
})
.collect()
pub fn get_cfg_keys(&self) -> impl Iterator<Item = &SmolStr> {
self.enabled.iter().map(|x| match x {
CfgAtom::Flag(key) => key,
CfgAtom::KeyValue { key, .. } => key,
})
}
pub fn get_cfg_values(&self, cfg_key: &str) -> Vec<&SmolStr> {
self.enabled
.iter()
.filter_map(|x| match x {
CfgAtom::KeyValue { key, value } if cfg_key == key => Some(value),
_ => None,
})
.collect()
pub fn get_cfg_values<'a>(
&'a self,
cfg_key: &'a str,
) -> impl Iterator<Item = &'a SmolStr> + 'a {
self.enabled.iter().filter_map(move |x| match x {
CfgAtom::KeyValue { key, value } if cfg_key == key => Some(value),
_ => None,
})
}
}