mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 06:15:45 +01:00
Move rtic macros to repo root, tune xtask
This commit is contained in:
parent
4124fbdd61
commit
9e445b3583
134 changed files with 31 additions and 29 deletions
36
rtic-macros/src/syntax/optimize.rs
Normal file
36
rtic-macros/src/syntax/optimize.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use std::collections::{BTreeSet, HashMap};
|
||||
|
||||
use crate::syntax::ast::App;
|
||||
|
||||
pub fn app(app: &mut App, settings: &Settings) {
|
||||
// "compress" priorities
|
||||
// If the user specified, for example, task priorities of "1, 3, 6",
|
||||
// compress them into "1, 2, 3" as to leave no gaps
|
||||
if settings.optimize_priorities {
|
||||
// all task priorities ordered in ascending order
|
||||
let priorities = app
|
||||
.hardware_tasks
|
||||
.values()
|
||||
.map(|task| Some(task.args.priority))
|
||||
.chain(
|
||||
app.software_tasks
|
||||
.values()
|
||||
.map(|task| Some(task.args.priority)),
|
||||
)
|
||||
.collect::<BTreeSet<_>>();
|
||||
|
||||
let map = priorities
|
||||
.iter()
|
||||
.cloned()
|
||||
.zip(1..)
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
for task in app.hardware_tasks.values_mut() {
|
||||
task.args.priority = map[&Some(task.args.priority)];
|
||||
}
|
||||
|
||||
for task in app.software_tasks.values_mut() {
|
||||
task.args.priority = map[&Some(task.args.priority)];
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue