2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-11-10 06:25:00 +00:00

Remove recursion

This commit is contained in:
Aode (Lion) 2021-10-20 20:36:10 -05:00
parent d69d261999
commit 1767942e31

View file

@ -174,40 +174,28 @@ pub(crate) fn build_chain(args: &[(String, String)], filename: String) -> (PathB
}
macro_rules! parse {
($inner:expr, $args:expr, $filename:expr, $x:ident, $k:expr, $v:expr) => {{
($inner:expr, $x:ident, $k:expr, $v:expr) => {{
if let Some(processor) = parse::<$x>($k, $v) {
return build(
(processor.path($inner.0), processor.command($inner.1)),
&$args[1..],
$filename,
);
}
return (processor.path($inner.0), processor.command($inner.1));
};
}};
}
fn build(
inner: (PathBuf, Vec<String>),
args: &[(String, String)],
filename: String,
) -> (PathBuf, Vec<String>) {
if args.len() == 0 {
return inner;
}
let (name, value) = &args[0];
parse!(inner, args, filename, Identity, name, value);
parse!(inner, args, filename, Thumbnail, name, value);
parse!(inner, args, filename, Resize, name, value);
parse!(inner, args, filename, Crop, name, value);
parse!(inner, args, filename, Blur, name, value);
let (path, args) =
args.into_iter()
.fold((PathBuf::default(), vec![]), |inner, (name, value)| {
parse!(inner, Identity, name, value);
parse!(inner, Thumbnail, name, value);
parse!(inner, Resize, name, value);
parse!(inner, Crop, name, value);
parse!(inner, Blur, name, value);
debug!("Skipping {}: {}, invalid", name, value);
build(inner, &args[1..], filename)
}
inner
});
build((PathBuf::default(), vec![]), args, filename)
(path.join(filename), args)
}
fn is_motion(s: &str) -> bool {