4 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -4064,6 +4064,7 @@ name = "rustc_lexer"
4064
4064
version = " 0.0.0"
4065
4065
dependencies = [
4066
4066
" expect-test" ,
4067
+ " memchr" ,
4067
4068
" unicode-properties" ,
4068
4069
" unicode-xid" ,
4069
4070
]
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ Rust lexer used by rustc. No stability guarantees are provided.
14
14
15
15
# Note that this crate purposefully does not depend on other rustc crates
16
16
[dependencies ]
17
+ memchr = " 2.7.4"
17
18
unicode-xid = " 0.2.0"
18
19
19
20
[dependencies .unicode-properties ]
Original file line number Diff line number Diff line change @@ -103,4 +103,11 @@ impl<'a> Cursor<'a> {
103
103
self . bump ( ) ;
104
104
}
105
105
}
106
+
107
+ pub ( crate ) fn eat_until ( & mut self , byte : u8 ) {
108
+ self . chars = match memchr:: memchr ( byte, self . as_str ( ) . as_bytes ( ) ) {
109
+ Some ( index) => self . as_str ( ) [ index..] . chars ( ) ,
110
+ None => "" . chars ( ) ,
111
+ }
112
+ }
106
113
}
Original file line number Diff line number Diff line change @@ -483,7 +483,7 @@ impl Cursor<'_> {
483
483
_ => None ,
484
484
} ;
485
485
486
- self . eat_while ( |c| c != '\n' ) ;
486
+ self . eat_until ( b '\n') ;
487
487
LineComment { doc_style }
488
488
}
489
489
@@ -888,7 +888,7 @@ impl Cursor<'_> {
888
888
// Skip the string contents and on each '#' character met, check if this is
889
889
// a raw string termination.
890
890
loop {
891
- self . eat_while ( |c| c != '"' ) ;
891
+ self . eat_until ( b '"') ;
892
892
893
893
if self . is_eof ( ) {
894
894
return Err ( RawStrError :: NoTerminator {
0 commit comments