Reduce allocations on project type detection (#32818)

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2025-06-16 17:06:16 -04:00 committed by GitHub
parent 7fb8ae0024
commit 701fa4daa8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -374,22 +374,28 @@ impl Telemetry {
return None;
}
let mut project_types: HashSet<String> = HashSet::new();
let mut project_types: HashSet<&str> = HashSet::new();
for (path, _, _) in updated_entries_set.iter() {
let Some(file_name) = path.file_name().and_then(|f| f.to_str()) else {
continue;
};
if file_name == "pnpm-lock.yaml" {
project_types.insert("pnpm".to_string());
let project_type = if file_name == "pnpm-lock.yaml" {
Some("pnpm")
} else if file_name == "yarn.lock" {
project_types.insert("yarn".to_string());
Some("yarn")
} else if file_name == "package.json" {
project_types.insert("node".to_string());
Some("node")
} else if DOTNET_PROJECT_FILES_REGEX.is_match(file_name) {
project_types.insert("dotnet".to_string());
}
Some("dotnet")
} else {
None
};
if let Some(project_type) = project_type {
project_types.insert(project_type);
};
}
if !project_types.is_empty() {
@ -398,7 +404,8 @@ impl Telemetry {
.insert(worktree_id);
}
let mut project_names_vec: Vec<String> = project_types.into_iter().collect();
let mut project_names_vec: Vec<String> =
project_types.into_iter().map(String::from).collect();
project_names_vec.sort();
Some(project_names_vec)
}