1
1
use std:: cmp:: min;
2
2
use std:: collections:: HashMap ;
3
3
use std:: hash:: { Hash , Hasher } ;
4
+ use std:: mem;
4
5
5
6
use regex:: { escape, Regex , RegexSet } ;
6
7
@@ -272,15 +273,12 @@ impl ResourceDef {
272
273
true
273
274
}
274
275
PatternType :: Dynamic ( ref re, ref names, len) => {
275
- let mut idx = 0 ;
276
276
let mut pos = 0 ;
277
- let mut segments: [ PathItem ; MAX_DYNAMIC_SEGMENTS ] =
278
- [ PathItem :: Static ( "" ) ; MAX_DYNAMIC_SEGMENTS ] ;
277
+ let mut segments: [ PathItem ; MAX_DYNAMIC_SEGMENTS ] = Default :: default ( ) ;
279
278
280
279
if let Some ( captures) = re. captures ( path. path ( ) ) {
281
280
for ( no, name) in names. iter ( ) . enumerate ( ) {
282
281
if let Some ( m) = captures. name ( & name) {
283
- idx += 1 ;
284
282
pos = m. end ( ) ;
285
283
segments[ no] = PathItem :: Segment ( m. start ( ) as u16 , m. end ( ) as u16 ) ;
286
284
} else {
@@ -294,24 +292,21 @@ impl ResourceDef {
294
292
} else {
295
293
return false ;
296
294
}
297
- for idx in 0 ..idx {
298
- path. add ( names[ idx ] , segments[ idx ] ) ;
295
+ for i in 0 ..names . len ( ) {
296
+ path. add ( names[ i ] , mem :: take ( & mut segments[ i ] ) ) ;
299
297
}
300
298
path. skip ( ( pos + len) as u16 ) ;
301
299
true
302
300
}
303
301
PatternType :: DynamicSet ( ref re, ref params) => {
304
302
if let Some ( idx) = re. matches ( path. path ( ) ) . into_iter ( ) . next ( ) {
305
303
let ( ref pattern, ref names, len) = params[ idx] ;
306
- let mut idx = 0 ;
307
304
let mut pos = 0 ;
308
- let mut segments: [ PathItem ; MAX_DYNAMIC_SEGMENTS ] =
309
- [ PathItem :: Static ( "" ) ; MAX_DYNAMIC_SEGMENTS ] ;
305
+ let mut segments: [ PathItem ; MAX_DYNAMIC_SEGMENTS ] = Default :: default ( ) ;
310
306
311
307
if let Some ( captures) = pattern. captures ( path. path ( ) ) {
312
308
for ( no, name) in names. iter ( ) . enumerate ( ) {
313
309
if let Some ( m) = captures. name ( & name) {
314
- idx += 1 ;
315
310
pos = m. end ( ) ;
316
311
segments[ no] =
317
312
PathItem :: Segment ( m. start ( ) as u16 , m. end ( ) as u16 ) ;
@@ -326,8 +321,8 @@ impl ResourceDef {
326
321
} else {
327
322
return false ;
328
323
}
329
- for idx in 0 ..idx {
330
- path. add ( names[ idx ] , segments[ idx ] ) ;
324
+ for i in 0 ..names . len ( ) {
325
+ path. add ( names[ i ] , mem :: take ( & mut segments[ i ] ) ) ;
331
326
}
332
327
path. skip ( ( pos + len) as u16 ) ;
333
328
true
@@ -385,15 +380,12 @@ impl ResourceDef {
385
380
true
386
381
}
387
382
PatternType :: Dynamic ( ref re, ref names, len) => {
388
- let mut idx = 0 ;
389
383
let mut pos = 0 ;
390
- let mut segments: [ PathItem ; MAX_DYNAMIC_SEGMENTS ] =
391
- [ PathItem :: Static ( "" ) ; MAX_DYNAMIC_SEGMENTS ] ;
384
+ let mut segments: [ PathItem ; MAX_DYNAMIC_SEGMENTS ] = Default :: default ( ) ;
392
385
393
386
if let Some ( captures) = re. captures ( res. resource_path ( ) . path ( ) ) {
394
387
for ( no, name) in names. iter ( ) . enumerate ( ) {
395
388
if let Some ( m) = captures. name ( & name) {
396
- idx += 1 ;
397
389
pos = m. end ( ) ;
398
390
segments[ no] = PathItem :: Segment ( m. start ( ) as u16 , m. end ( ) as u16 ) ;
399
391
} else {
@@ -413,8 +405,8 @@ impl ResourceDef {
413
405
}
414
406
415
407
let path = res. resource_path ( ) ;
416
- for idx in 0 ..idx {
417
- path. add ( names[ idx ] , segments[ idx ] ) ;
408
+ for i in 0 ..names . len ( ) {
409
+ path. add ( names[ i ] , mem :: take ( & mut segments[ i ] ) ) ;
418
410
}
419
411
path. skip ( ( pos + len) as u16 ) ;
420
412
true
@@ -423,15 +415,12 @@ impl ResourceDef {
423
415
let path = res. resource_path ( ) . path ( ) ;
424
416
if let Some ( idx) = re. matches ( path) . into_iter ( ) . next ( ) {
425
417
let ( ref pattern, ref names, len) = params[ idx] ;
426
- let mut idx = 0 ;
427
418
let mut pos = 0 ;
428
- let mut segments: [ PathItem ; MAX_DYNAMIC_SEGMENTS ] =
429
- [ PathItem :: Static ( "" ) ; MAX_DYNAMIC_SEGMENTS ] ;
419
+ let mut segments: [ PathItem ; MAX_DYNAMIC_SEGMENTS ] = Default :: default ( ) ;
430
420
431
421
if let Some ( captures) = pattern. captures ( path) {
432
422
for ( no, name) in names. iter ( ) . enumerate ( ) {
433
423
if let Some ( m) = captures. name ( & name) {
434
- idx += 1 ;
435
424
pos = m. end ( ) ;
436
425
segments[ no] =
437
426
PathItem :: Segment ( m. start ( ) as u16 , m. end ( ) as u16 ) ;
@@ -452,8 +441,8 @@ impl ResourceDef {
452
441
}
453
442
454
443
let path = res. resource_path ( ) ;
455
- for idx in 0 ..idx {
456
- path. add ( names[ idx ] , segments[ idx ] ) ;
444
+ for i in 0 ..names . len ( ) {
445
+ path. add ( names[ i ] , mem :: take ( & mut segments[ i ] ) ) ;
457
446
}
458
447
path. skip ( ( pos + len) as u16 ) ;
459
448
true
0 commit comments