@@ -210,7 +210,7 @@ fn vpath(p: &Path) -> std::io::Result<VPath> {
210
210
segment_it. next ( ) ;
211
211
}
212
212
213
- let mut base_items: Vec < & str > = Vec :: new ( ) ;
213
+ let mut base_items: Vec < & str > = Vec :: with_capacity ( 10 ) ;
214
214
215
215
let mut virtual_items: Option < Vec < & str > > = None ;
216
216
let mut internal_items: Option < Vec < & str > > = None ;
@@ -248,13 +248,13 @@ fn vpath(p: &Path) -> std::io::Result<VPath> {
248
248
}
249
249
250
250
virtual_items = Some ( acc_segments) ;
251
- internal_items = Some ( vec ! [ ] ) ;
251
+ internal_items = Some ( Vec :: with_capacity ( 10 ) ) ;
252
252
253
253
continue ;
254
254
}
255
255
256
256
if segment. len ( ) > 4 && segment. ends_with ( ".zip" ) {
257
- zip_items = Some ( vec ! [ ] ) ;
257
+ zip_items = Some ( Vec :: with_capacity ( 10 ) ) ;
258
258
}
259
259
260
260
if let Some ( virtual_segments) = & mut virtual_items {
@@ -268,14 +268,7 @@ fn vpath(p: &Path) -> std::io::Result<VPath> {
268
268
}
269
269
}
270
270
271
- let mut base_path = base_items. join ( "/" ) ;
272
-
273
- // Don't forget to add back the leading slash we removed earlier
274
- if normalized_relative_path != normalized_path {
275
- base_path. insert ( 0 , '/' ) ;
276
- }
277
-
278
- let virtual_info = match ( virtual_items, internal_items) {
271
+ let virtual_segments = match ( virtual_items, internal_items) {
279
272
( Some ( virtual_segments) , Some ( internal_segments) ) => {
280
273
Some ( ( virtual_segments. join ( "/" ) , internal_segments. join ( "/" ) ) )
281
274
}
@@ -284,20 +277,34 @@ fn vpath(p: &Path) -> std::io::Result<VPath> {
284
277
} ;
285
278
286
279
if let Some ( zip_segments) = zip_items {
280
+ let mut base_path = base_items. join ( "/" ) ;
281
+
282
+ // Don't forget to add back the leading slash we removed earlier
283
+ if normalized_relative_path != normalized_path {
284
+ base_path. insert ( 0 , '/' ) ;
285
+ }
286
+
287
287
if !zip_segments. is_empty ( ) {
288
288
return Ok ( VPath :: Zip ( ZipInfo {
289
289
base_path,
290
- virtual_segments : virtual_info ,
290
+ virtual_segments,
291
291
zip_path : zip_segments. join ( "/" ) ,
292
292
} ) ) ;
293
293
}
294
294
}
295
295
296
- if let Some ( virtual_info) = virtual_info {
297
- return Ok ( VPath :: Virtual ( VirtualInfo { base_path, virtual_segments : virtual_info } ) ) ;
296
+ if let Some ( virtual_segments) = virtual_segments {
297
+ let mut base_path = base_items. join ( "/" ) ;
298
+
299
+ // Don't forget to add back the leading slash we removed earlier
300
+ if normalized_relative_path != normalized_path {
301
+ base_path. insert ( 0 , '/' ) ;
302
+ }
303
+
304
+ return Ok ( VPath :: Virtual ( VirtualInfo { base_path, virtual_segments } ) ) ;
298
305
}
299
306
300
- Ok ( VPath :: Native ( PathBuf :: from ( base_path ) ) )
307
+ Ok ( VPath :: Native ( PathBuf :: from ( normalized_path ) ) )
301
308
}
302
309
303
310
#[ cfg( test) ]
0 commit comments