@@ -104,48 +104,49 @@ impl FileList {
104
104
105
105
let files: Value = rows. get ( 0 ) . get_opt ( 5 ) . unwrap ( ) . ok ( ) ?;
106
106
107
+ let mut file_list = Vec :: new ( ) ;
107
108
if let Some ( files) = files. as_array ( ) {
108
- let mut file_list: Vec < File > = files
109
- . iter ( )
110
- . filter_map ( |file| {
111
- if let Some ( file) = file. as_array ( ) {
112
- let mime = file[ 0 ] . as_str ( ) . unwrap ( ) ;
113
- let path = file[ 1 ] . as_str ( ) . unwrap ( ) ;
114
-
115
- // skip .cargo-ok generated by cargo
116
- if path == ".cargo-ok" {
117
- return None ;
118
- }
109
+ file_list. reserve ( files. len ( ) ) ;
119
110
120
- // look only files for req_path
121
- if path. starts_with ( & req_path) {
122
- // remove req_path from path to reach files in this directory
123
- let path = path. replace ( & req_path, "" ) ;
124
- let path_splited: Vec < & str > = path. split ( '/' ) . collect ( ) ;
125
-
126
- // if path have '/' it is a directory
127
- let ftype = if path_splited. len ( ) > 1 {
128
- FileType :: Dir
129
- } else if mime. starts_with ( "text" ) && path_splited[ 0 ] . ends_with ( ".rs" ) {
130
- FileType :: RustSource
131
- } else if mime. starts_with ( "text" ) {
132
- FileType :: Text
133
- } else {
134
- FileType :: Binary
135
- } ;
136
-
137
- let file = File {
138
- name : path_splited[ 0 ] . to_owned ( ) ,
139
- file_type : ftype,
140
- } ;
141
-
142
- return Some ( file) ;
143
- }
111
+ for file in files {
112
+ if let Some ( file) = file. as_array ( ) {
113
+ let mime = file[ 0 ] . as_str ( ) . unwrap ( ) ;
114
+ let path = file[ 1 ] . as_str ( ) . unwrap ( ) ;
115
+
116
+ // skip .cargo-ok generated by cargo
117
+ if path == ".cargo-ok" {
118
+ return None ;
144
119
}
145
120
146
- None
147
- } )
148
- . collect :: < Vec < _ > > ( ) ;
121
+ // look only files for req_path
122
+ if path. starts_with ( & req_path) {
123
+ // remove req_path from path to reach files in this directory
124
+ let path = path. replace ( & req_path, "" ) ;
125
+ let path_splited: Vec < & str > = path. split ( '/' ) . collect ( ) ;
126
+
127
+ // if path have '/' it is a directory
128
+ let ftype = if path_splited. len ( ) > 1 {
129
+ FileType :: Dir
130
+ } else if mime. starts_with ( "text" ) && path_splited[ 0 ] . ends_with ( ".rs" ) {
131
+ FileType :: RustSource
132
+ } else if mime. starts_with ( "text" ) {
133
+ FileType :: Text
134
+ } else {
135
+ FileType :: Binary
136
+ } ;
137
+
138
+ let file = File {
139
+ name : path_splited[ 0 ] . to_owned ( ) ,
140
+ file_type : ftype,
141
+ } ;
142
+
143
+ // avoid adding duplicates, a directory may occur more than once
144
+ if !file_list. contains ( & file) {
145
+ file_list. push ( file) ;
146
+ }
147
+ }
148
+ }
149
+ }
149
150
150
151
if file_list. is_empty ( ) {
151
152
return None ;
@@ -162,9 +163,6 @@ impl FileList {
162
163
}
163
164
} ) ;
164
165
165
- // avoid adding duplicates, a directory may occur more than once
166
- file_list. dedup ( ) ;
167
-
168
166
Some ( FileList {
169
167
metadata : MetaData {
170
168
name : rows. get ( 0 ) . get ( 0 ) ,
0 commit comments