Skip to content

Commit

Permalink
refactor: do not clone configs Vec for unprocessed imports
Browse files Browse the repository at this point in the history
Each iteration of a load only considers what is new since the last
round.

The entire configs vector does not need to be cloned for working on the
small tail slice of unprocessed configs.
  • Loading branch information
lavafroth committed May 13, 2024
1 parent 7999a9b commit c24e900
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions swhkd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ impl Config {

pub fn load_and_merge(config: Self) -> Result<Vec<Self>, Error> {
let mut configs = vec![config];
let mut prev_count = 0;
let mut current_count = configs.len();
while prev_count != current_count {
prev_count = configs.len();
for config in configs.clone() {
for import in Self::load_to_configs(&config)? {
let mut processed = 0;

while processed != configs.len() {
let unprocessed_range = processed..configs.len();
for unprocessed in unprocessed_range {
for import in Self::load_to_configs(&configs[unprocessed])? {
if !configs.contains(&import) {
configs.push(import);
}
}
processed += 1;
}
current_count = configs.len();
}
Ok(configs)
}
Expand Down

0 comments on commit c24e900

Please sign in to comment.