@@ -2035,19 +2035,13 @@ mod traits {
2035
2035
type Output = str ;
2036
2036
#[ inline]
2037
2037
fn get ( self , slice : & str ) -> Option < & Self :: Output > {
2038
- if let Some ( end) = self . end . checked_add ( 1 ) {
2039
- ( self . start ..end) . get ( slice)
2040
- } else {
2041
- None
2042
- }
2038
+ if self . end == usize:: max_value ( ) { None }
2039
+ else { ( self . start ..self . end +1 ) . get ( slice) }
2043
2040
}
2044
2041
#[ inline]
2045
2042
fn get_mut ( self , slice : & mut str ) -> Option < & mut Self :: Output > {
2046
- if let Some ( end) = self . end . checked_add ( 1 ) {
2047
- ( self . start ..end) . get_mut ( slice)
2048
- } else {
2049
- None
2050
- }
2043
+ if self . end == usize:: max_value ( ) { None }
2044
+ else { ( self . start ..self . end +1 ) . get_mut ( slice) }
2051
2045
}
2052
2046
#[ inline]
2053
2047
unsafe fn get_unchecked ( self , slice : & str ) -> & Self :: Output {
@@ -2076,29 +2070,21 @@ mod traits {
2076
2070
type Output = str ;
2077
2071
#[ inline]
2078
2072
fn get ( self , slice : & str ) -> Option < & Self :: Output > {
2079
- if self . end < usize:: max_value ( ) && slice. is_char_boundary ( self . end + 1 ) {
2080
- Some ( unsafe { self . get_unchecked ( slice) } )
2081
- } else {
2082
- None
2083
- }
2073
+ if self . end == usize:: max_value ( ) { None }
2074
+ else { ( ..self . end +1 ) . get ( slice) }
2084
2075
}
2085
2076
#[ inline]
2086
2077
fn get_mut ( self , slice : & mut str ) -> Option < & mut Self :: Output > {
2087
- if self . end < usize:: max_value ( ) && slice. is_char_boundary ( self . end + 1 ) {
2088
- Some ( unsafe { self . get_unchecked_mut ( slice) } )
2089
- } else {
2090
- None
2091
- }
2078
+ if self . end == usize:: max_value ( ) { None }
2079
+ else { ( ..self . end +1 ) . get_mut ( slice) }
2092
2080
}
2093
2081
#[ inline]
2094
2082
unsafe fn get_unchecked ( self , slice : & str ) -> & Self :: Output {
2095
- let ptr = slice. as_ptr ( ) ;
2096
- super :: from_utf8_unchecked ( slice:: from_raw_parts ( ptr, self . end + 1 ) )
2083
+ ( ..self . end +1 ) . get_unchecked ( slice)
2097
2084
}
2098
2085
#[ inline]
2099
2086
unsafe fn get_unchecked_mut ( self , slice : & mut str ) -> & mut Self :: Output {
2100
- let ptr = slice. as_ptr ( ) ;
2101
- super :: from_utf8_unchecked_mut ( slice:: from_raw_parts_mut ( ptr as * mut u8 , self . end + 1 ) )
2087
+ ( ..self . end +1 ) . get_unchecked_mut ( slice)
2102
2088
}
2103
2089
#[ inline]
2104
2090
fn index ( self , slice : & str ) -> & Self :: Output {
0 commit comments