File tree 2 files changed +29
-2
lines changed
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -1015,7 +1015,7 @@ impl AsRef<str> for String {
1015
1015
impl < ' a > From < & ' a str > for String {
1016
1016
#[ inline]
1017
1017
fn from ( s : & ' a str ) -> String {
1018
- s . to_string ( )
1018
+ String { vec : < [ _ ] > :: to_vec ( s . as_bytes ( ) ) }
1019
1019
}
1020
1020
}
1021
1021
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ use std::iter::repeat;
13
13
use std:: str:: Utf8Error ;
14
14
use std:: string:: as_string;
15
15
16
- use test:: Bencher ;
16
+ use test:: { self , Bencher } ;
17
17
18
18
#[ test]
19
19
fn test_as_string ( ) {
@@ -450,3 +450,30 @@ fn bench_exact_size_shrink_to_fit(b: &mut Bencher) {
450
450
r
451
451
} ) ;
452
452
}
453
+
454
+ #[ bench]
455
+ fn bench_from_str ( b : & mut Bencher ) {
456
+ let s = "Hello there, the quick brown fox jumped over the lazy dog! \
457
+ Lorem ipsum dolor sit amet, consectetur. ";
458
+ b. iter ( || {
459
+ test:: black_box ( String :: from_str ( s) ) ;
460
+ } )
461
+ }
462
+
463
+ #[ bench]
464
+ fn bench_from ( b : & mut Bencher ) {
465
+ let s = "Hello there, the quick brown fox jumped over the lazy dog! \
466
+ Lorem ipsum dolor sit amet, consectetur. ";
467
+ b. iter ( || {
468
+ test:: black_box ( String :: from ( s) ) ;
469
+ } )
470
+ }
471
+
472
+ #[ bench]
473
+ fn bench_to_string ( b : & mut Bencher ) {
474
+ let s = "Hello there, the quick brown fox jumped over the lazy dog! \
475
+ Lorem ipsum dolor sit amet, consectetur. ";
476
+ b. iter ( || {
477
+ test:: black_box ( s. to_string ( ) ) ;
478
+ } )
479
+ }
You can’t perform that action at this time.
0 commit comments