Skip to content

Commit b2cda4c

Browse files
committed
remove allocation
1 parent 8f26ca4 commit b2cda4c

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

src/sudoers/mod.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,22 @@ fn group_cmd_specs_per_runas<'a>(
226226
let origin = |runas: Option<&RunAs>| runas.map(|r| r as *const _);
227227

228228
let mut cmnd_specs = cmnd_specs.peekable();
229-
let mut entries = vec![];
230-
231-
while let Some(&(cur_runas, _)) = cmnd_specs.peek() {
232-
let specs = peeking_take_while(&mut cmnd_specs, |&(runas, _)| {
233-
origin(runas) == origin(cur_runas)
234-
});
235-
236-
entries.push(Entry::new(
237-
cur_runas,
238-
specs.map(|x| x.1).collect(),
239-
cmnd_aliases,
240-
));
241-
}
242229

243-
entries.into_iter()
230+
std::iter::from_fn(move || {
231+
if let Some(&(cur_runas, _)) = cmnd_specs.peek() {
232+
let specs = peeking_take_while(&mut cmnd_specs, |&(runas, _)| {
233+
origin(runas) == origin(cur_runas)
234+
});
235+
236+
Some(Entry::new(
237+
cur_runas,
238+
specs.map(|x| x.1).collect(),
239+
cmnd_aliases,
240+
))
241+
} else {
242+
None
243+
}
244+
})
244245
}
245246

246247
fn read_sudoers<R: io::Read>(mut reader: R) -> io::Result<Vec<basic_parser::Parsed<Sudo>>> {

0 commit comments

Comments
 (0)