File tree 1 file changed +21
-8
lines changed
library/coretests/benches/str
1 file changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -48,27 +48,40 @@ macro_rules! define_benches {
48
48
}
49
49
50
50
define_benches ! {
51
- fn case00_libcore ( s: & str ) {
52
- libcore ( s)
51
+ fn case00_chars_count ( s: & str ) {
52
+ chars_count ( s)
53
53
}
54
54
55
- fn case01_filter_count_cont_bytes( s: & str ) {
55
+ fn case01_chars_advance_by( s: & str ) {
56
+ chars_advance_by( s)
57
+ }
58
+
59
+ fn case02_filter_count_cont_bytes( s: & str ) {
56
60
filter_count_cont_bytes( s)
57
61
}
58
62
59
- fn case02_iter_increment ( s: & str ) {
60
- iterator_increment ( s)
63
+ fn case03_iter_chars_increment ( s: & str ) {
64
+ iter_chars_increment ( s)
61
65
}
62
66
63
- fn case03_manual_char_len ( s: & str ) {
67
+ fn case04_manual_char_len ( s: & str ) {
64
68
manual_char_len( s)
65
69
}
66
70
}
67
71
68
- fn libcore ( s : & str ) -> usize {
72
+ fn chars_count ( s : & str ) -> usize {
69
73
s. chars ( ) . count ( )
70
74
}
71
75
76
+ fn chars_advance_by ( s : & str ) -> usize {
77
+ let mut iter = s. chars ( ) ;
78
+ let remaining = match iter. advance_by ( usize:: MAX ) {
79
+ Ok ( ( ) ) => 0 ,
80
+ Err ( remaining) => remaining. get ( ) ,
81
+ } ;
82
+ usize:: MAX - remaining
83
+ }
84
+
72
85
#[ inline]
73
86
fn utf8_is_cont_byte ( byte : u8 ) -> bool {
74
87
( byte as i8 ) < -64
@@ -78,7 +91,7 @@ fn filter_count_cont_bytes(s: &str) -> usize {
78
91
s. as_bytes ( ) . iter ( ) . filter ( |& & byte| !utf8_is_cont_byte ( byte) ) . count ( )
79
92
}
80
93
81
- fn iterator_increment ( s : & str ) -> usize {
94
+ fn iter_chars_increment ( s : & str ) -> usize {
82
95
let mut c = 0 ;
83
96
for _ in s. chars ( ) {
84
97
c += 1 ;
You can’t perform that action at this time.
0 commit comments