Skip to content

Commit 7a023d9

Browse files
committed
initializing vectors with capacity
1 parent 8063f3a commit 7a023d9

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ignore = "0.4.23"
1515
itertools = "0.13.0"
1616
path-clean = "1.0.1"
1717
lazy_static = "1.5.0"
18+
num_cpus = "1.16.0"
1819
rayon = "1.10.0"
1920
regex = "1.11.1"
2021
serde = { version = "1.0.214", features = ["derive"] }

src/project_builder.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub struct ProjectBuilder<'a> {
3535
pub codeowners_file_path: PathBuf,
3636
}
3737

38+
const INITIAL_VECTOR_CAPACITY: usize = 1000;
39+
3840
impl<'a> ProjectBuilder<'a> {
3941
pub fn new(config: &'a Config, base_path: PathBuf, codeowners_file_path: PathBuf) -> Self {
4042
Self {
@@ -46,8 +48,7 @@ impl<'a> ProjectBuilder<'a> {
4648

4749
#[instrument(level = "debug", skip_all)]
4850
pub fn build(&mut self) -> Result<Project, Error> {
49-
let mut entry_types = Vec::new();
50-
51+
let mut entry_types = Vec::with_capacity(INITIAL_VECTOR_CAPACITY);
5152
let mut builder = WalkBuilder::new(&self.base_path);
5253
builder.hidden(false);
5354
let walkdir = builder.build();
@@ -68,22 +69,20 @@ impl<'a> ProjectBuilder<'a> {
6869
if is_dir {
6970
return Ok(EntryType::Directory(absolute_path.to_owned(), relative_path.to_owned()));
7071
}
71-
let file_name = relative_path.file_name().expect("expected a file_name");
72-
73-
match file_name.to_str().unwrap_or("") {
74-
name if name.eq_ignore_ascii_case("package.yml")
75-
&& matches_globs(relative_path.parent().unwrap(), &self.config.ruby_package_paths) =>
76-
{
72+
let file_name = relative_path
73+
.file_name()
74+
.expect("expected a file_name")
75+
.to_string_lossy()
76+
.to_lowercase();
77+
78+
match file_name.as_str() {
79+
name if name == "package.yml" && matches_globs(relative_path.parent().unwrap(), &self.config.ruby_package_paths) => {
7780
Ok(EntryType::RubyPackage(absolute_path.to_owned(), relative_path.to_owned()))
7881
}
79-
name if name.eq_ignore_ascii_case("package.json")
80-
&& matches_globs(relative_path.parent().unwrap(), &self.config.javascript_package_paths) =>
81-
{
82+
name if name == "package.json" && matches_globs(relative_path.parent().unwrap(), &self.config.javascript_package_paths) => {
8283
Ok(EntryType::JavascriptPackage(absolute_path.to_owned(), relative_path.to_owned()))
8384
}
84-
name if name.eq_ignore_ascii_case(".codeowner") => {
85-
Ok(EntryType::CodeownerFile(absolute_path.to_owned(), relative_path.to_owned()))
86-
}
85+
".codeowner" => Ok(EntryType::CodeownerFile(absolute_path.to_owned(), relative_path.to_owned())),
8786
_ if matches_globs(&relative_path, &self.config.team_file_glob) => {
8887
Ok(EntryType::TeamFile(absolute_path.to_owned(), relative_path.to_owned()))
8988
}
@@ -101,7 +100,7 @@ impl<'a> ProjectBuilder<'a> {
101100
.fold(
102101
|| {
103102
(
104-
Vec::<ProjectFile>::new(),
103+
Vec::<ProjectFile>::with_capacity(INITIAL_VECTOR_CAPACITY),
105104
Vec::<Package>::new(),
106105
Vec::<VendoredGem>::new(),
107106
Vec::<DirectoryCodeownersFile>::new(),
@@ -223,7 +222,6 @@ fn build_project_file(path: PathBuf) -> ProjectFile {
223222
};
224223

225224
let first_line = content.lines().next();
226-
227225
let Some(first_line) = first_line else {
228226
return ProjectFile { path, owner: None };
229227
};

0 commit comments

Comments
 (0)