File tree Expand file tree Collapse file tree 3 files changed +14
-8
lines changed Expand file tree Collapse file tree 3 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -554,7 +554,7 @@ impl Config {
554
554
555
555
/// http://www.unicode.org/reports/tr46/#ToASCII
556
556
pub fn to_ascii ( self , domain : & str ) -> Result < String , Errors > {
557
- let mut result = String :: new ( ) ;
557
+ let mut result = String :: with_capacity ( domain . len ( ) ) ;
558
558
let mut codec = Idna :: new ( self ) ;
559
559
codec. to_ascii ( domain, & mut result) . map ( |( ) | result)
560
560
}
Original file line number Diff line number Diff line change @@ -12,5 +12,12 @@ fn short(bench: &mut Bencher) {
12
12
bench. iter ( || black_box ( url) . parse :: < Url > ( ) . unwrap ( ) ) ;
13
13
}
14
14
15
- benchmark_group ! ( benches, short) ;
15
+ fn long ( bench : & mut Bencher ) {
16
+ let url = "https://example.com/parkbench?tre=es&st=uff" ;
17
+
18
+ bench. bytes = url. len ( ) as u64 ;
19
+ bench. iter ( || black_box ( url) . parse :: < Url > ( ) . unwrap ( ) ) ;
20
+ }
21
+
22
+ benchmark_group ! ( benches, short, long) ;
16
23
benchmark_main ! ( benches) ;
Original file line number Diff line number Diff line change @@ -1216,13 +1216,11 @@ impl<'a> Parser<'a> {
1216
1216
}
1217
1217
}
1218
1218
}
1219
- // Going from &str to String to &str to please the 1.33.0 borrow checker
1220
- let before_slash_string = if ends_with_slash {
1221
- self . serialization [ segment_start..self . serialization . len ( ) - 1 ] . to_owned ( )
1219
+ let segment_before_slash = if ends_with_slash {
1220
+ & self . serialization [ segment_start..self . serialization . len ( ) - 1 ]
1222
1221
} else {
1223
- self . serialization [ segment_start..self . serialization . len ( ) ] . to_owned ( )
1222
+ & self . serialization [ segment_start..self . serialization . len ( ) ]
1224
1223
} ;
1225
- let segment_before_slash: & str = & before_slash_string;
1226
1224
match segment_before_slash {
1227
1225
// If buffer is a double-dot path segment, shorten url’s path,
1228
1226
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
@@ -1412,7 +1410,8 @@ impl<'a> Parser<'a> {
1412
1410
scheme_end : u32 ,
1413
1411
mut input : Input < ' i > ,
1414
1412
) -> Option < Input < ' i > > {
1415
- let mut query = String :: new ( ) ; // FIXME: use a streaming decoder instead
1413
+ let len = input. chars . as_str ( ) . len ( ) ;
1414
+ let mut query = String :: with_capacity ( len) ; // FIXME: use a streaming decoder instead
1416
1415
let mut remaining = None ;
1417
1416
while let Some ( c) = input. next ( ) {
1418
1417
if c == '#' && self . context == Context :: UrlParser {
You can’t perform that action at this time.
0 commit comments