File tree Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -126,16 +126,28 @@ trait CheckRaw {
126
126
src : & str ,
127
127
mut callback : impl FnMut ( Range < usize > , Result < Self :: RawUnit , EscapeError > ) ,
128
128
) {
129
- src. char_indices ( ) . for_each ( |( pos, c) | {
130
- callback (
131
- pos..pos + c. len_utf8 ( ) ,
132
- if c == '\r' {
133
- Err ( EscapeError :: BareCarriageReturnInRawString )
134
- } else {
135
- Self :: char2raw_unit ( c)
136
- } ,
137
- ) ;
138
- } ) ;
129
+ let mut chars = src. chars ( ) ;
130
+ while let Some ( c) = chars. next ( ) {
131
+ let start = src. len ( ) - chars. as_str ( ) . len ( ) - c. len_utf8 ( ) ;
132
+ let res = match c {
133
+ '\r' => Err ( EscapeError :: BareCarriageReturn ) ,
134
+ _ => Self :: char2raw_unit ( c) ,
135
+ } ;
136
+ let end = src. len ( ) - chars. as_str ( ) . len ( ) ;
137
+ callback ( start..end, res) ;
138
+ }
139
+
140
+ // Unfortunately, it is a bit unclear whether the following equivalent code is slower or faster: bug 141855
141
+ // src.char_indices().for_each(|(pos, c)| {
142
+ // callback(
143
+ // pos..pos + c.len_utf8(),
144
+ // if c == '\r' {
145
+ // Err(EscapeError::BareCarriageReturnInRawString)
146
+ // } else {
147
+ // Self::char2raw_unit(c)
148
+ // },
149
+ // );
150
+ // });
139
151
}
140
152
}
141
153
You can’t perform that action at this time.
0 commit comments