@@ -35,6 +35,8 @@ pub struct ProjectBuilder<'a> {
35
35
pub codeowners_file_path : PathBuf ,
36
36
}
37
37
38
+ const INITIAL_VECTOR_CAPACITY : usize = 1000 ;
39
+
38
40
impl < ' a > ProjectBuilder < ' a > {
39
41
pub fn new ( config : & ' a Config , base_path : PathBuf , codeowners_file_path : PathBuf ) -> Self {
40
42
Self {
@@ -46,8 +48,7 @@ impl<'a> ProjectBuilder<'a> {
46
48
47
49
#[ instrument( level = "debug" , skip_all) ]
48
50
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 ) ;
51
52
let mut builder = WalkBuilder :: new ( & self . base_path ) ;
52
53
builder. hidden ( false ) ;
53
54
let walkdir = builder. build ( ) ;
@@ -56,7 +57,9 @@ impl<'a> ProjectBuilder<'a> {
56
57
let entry = entry. change_context ( Error :: Io ) ?;
57
58
entry_types. push ( self . build_entry_type ( entry) ?) ;
58
59
}
59
- self . build_project_from_entry_types ( entry_types)
60
+ let project = self . build_project_from_entry_types ( entry_types) ?;
61
+
62
+ Ok ( project)
60
63
}
61
64
62
65
fn build_entry_type ( & mut self , entry : ignore:: DirEntry ) -> Result < EntryType , Error > {
@@ -68,22 +71,20 @@ impl<'a> ProjectBuilder<'a> {
68
71
if is_dir {
69
72
return Ok ( EntryType :: Directory ( absolute_path. to_owned ( ) , relative_path. to_owned ( ) ) ) ;
70
73
}
71
- let file_name = relative_path. file_name ( ) . expect ( "expected a file_name" ) ;
74
+ let file_name = relative_path
75
+ . file_name ( )
76
+ . expect ( "expected a file_name" )
77
+ . to_string_lossy ( )
78
+ . to_lowercase ( ) ;
72
79
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
- {
80
+ match file_name. as_str ( ) {
81
+ name if name == "package.yml" && matches_globs ( relative_path. parent ( ) . unwrap ( ) , & self . config . ruby_package_paths ) => {
77
82
Ok ( EntryType :: RubyPackage ( absolute_path. to_owned ( ) , relative_path. to_owned ( ) ) )
78
83
}
79
- name if name. eq_ignore_ascii_case ( "package.json" )
80
- && matches_globs ( relative_path. parent ( ) . unwrap ( ) , & self . config . javascript_package_paths ) =>
81
- {
84
+ name if name == "package.json" && matches_globs ( relative_path. parent ( ) . unwrap ( ) , & self . config . javascript_package_paths ) => {
82
85
Ok ( EntryType :: JavascriptPackage ( absolute_path. to_owned ( ) , relative_path. to_owned ( ) ) )
83
86
}
84
- name if name. eq_ignore_ascii_case ( ".codeowner" ) => {
85
- Ok ( EntryType :: CodeownerFile ( absolute_path. to_owned ( ) , relative_path. to_owned ( ) ) )
86
- }
87
+ ".codeowner" => Ok ( EntryType :: CodeownerFile ( absolute_path. to_owned ( ) , relative_path. to_owned ( ) ) ) ,
87
88
_ if matches_globs ( & relative_path, & self . config . team_file_glob ) => {
88
89
Ok ( EntryType :: TeamFile ( absolute_path. to_owned ( ) , relative_path. to_owned ( ) ) )
89
90
}
@@ -101,7 +102,7 @@ impl<'a> ProjectBuilder<'a> {
101
102
. fold (
102
103
|| {
103
104
(
104
- Vec :: < ProjectFile > :: new ( ) ,
105
+ Vec :: < ProjectFile > :: with_capacity ( INITIAL_VECTOR_CAPACITY ) ,
105
106
Vec :: < Package > :: new ( ) ,
106
107
Vec :: < VendoredGem > :: new ( ) ,
107
108
Vec :: < DirectoryCodeownersFile > :: new ( ) ,
@@ -223,7 +224,6 @@ fn build_project_file(path: PathBuf) -> ProjectFile {
223
224
} ;
224
225
225
226
let first_line = content. lines ( ) . next ( ) ;
226
-
227
227
let Some ( first_line) = first_line else {
228
228
return ProjectFile { path, owner : None } ;
229
229
} ;
0 commit comments