File tree 1 file changed +7
-6
lines changed
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -185,8 +185,9 @@ impl str {
185
185
/// ```
186
186
#[ must_use]
187
187
#[ stable( feature = "is_char_boundary" , since = "1.9.0" ) ]
188
+ #[ rustc_const_unstable( feature = "const_is_char_boundary" , issue = "131516" ) ]
188
189
#[ inline]
189
- pub fn is_char_boundary ( & self , index : usize ) -> bool {
190
+ pub const fn is_char_boundary ( & self , index : usize ) -> bool {
190
191
// 0 is always ok.
191
192
// Test for 0 explicitly so that it can optimize out the check
192
193
// easily and skip reading string data for that case.
@@ -195,8 +196,8 @@ impl str {
195
196
return true ;
196
197
}
197
198
198
- match self . as_bytes ( ) . get ( index ) {
199
- // For `None ` we have two options:
199
+ if index >= self . len ( ) {
200
+ // For `true ` we have two options:
200
201
//
201
202
// - index == self.len()
202
203
// Empty strings are valid, so return true
@@ -205,9 +206,9 @@ impl str {
205
206
//
206
207
// The check is placed exactly here, because it improves generated
207
208
// code on higher opt-levels. See PR #84751 for more details.
208
- None => index == self . len ( ) ,
209
-
210
- Some ( & b ) => b . is_utf8_char_boundary ( ) ,
209
+ index == self . len ( )
210
+ } else {
211
+ self . as_bytes ( ) [ index ] . is_utf8_char_boundary ( )
211
212
}
212
213
}
213
214
You can’t perform that action at this time.
0 commit comments