|
1 | 1 | use crate::{ |
2 | 2 | core::{ |
3 | | - common::{collect_owners, collect_tags, get_repo_hash}, |
| 3 | + common::get_repo_hash, |
4 | 4 | parse::parse_repo, |
5 | 5 | resolver::find_owners_and_tags_for_file, |
6 | 6 | types::{ |
@@ -93,27 +93,21 @@ pub fn build_cache( |
93 | 93 | // Print newline after processing is complete |
94 | 94 | println!("\r\x1b[K✅ Processed {} files successfully", total_files); |
95 | 95 |
|
96 | | - // Process each owner |
97 | | - let owners = collect_owners(&entries); |
98 | | - owners.iter().for_each(|owner| { |
99 | | - let paths = owners_map.entry(owner.clone()).or_insert_with(Vec::new); |
100 | | - for file_entry in &file_entries { |
101 | | - if file_entry.owners.contains(owner) { |
102 | | - paths.push(file_entry.path.clone()); |
103 | | - } |
| 96 | + // Build owner and tag maps in a single pass through file_entries - O(files) instead of O(owners × files) |
| 97 | + for file_entry in &file_entries { |
| 98 | + for owner in &file_entry.owners { |
| 99 | + owners_map |
| 100 | + .entry(owner.clone()) |
| 101 | + .or_insert_with(Vec::new) |
| 102 | + .push(file_entry.path.clone()); |
104 | 103 | } |
105 | | - }); |
106 | | - |
107 | | - // Process each tag |
108 | | - let tags = collect_tags(&entries); |
109 | | - tags.iter().for_each(|tag| { |
110 | | - let paths = tags_map.entry(tag.clone()).or_insert_with(Vec::new); |
111 | | - for file_entry in &file_entries { |
112 | | - if file_entry.tags.contains(tag) { |
113 | | - paths.push(file_entry.path.clone()); |
114 | | - } |
| 104 | + for tag in &file_entry.tags { |
| 105 | + tags_map |
| 106 | + .entry(tag.clone()) |
| 107 | + .or_insert_with(Vec::new) |
| 108 | + .push(file_entry.path.clone()); |
115 | 109 | } |
116 | | - }); |
| 110 | + } |
117 | 111 |
|
118 | 112 | Ok(CodeownersCache { |
119 | 113 | hash, |
|
0 commit comments