@@ -563,7 +563,6 @@ impl Cursor<'_> {
563563 self . eat_while ( |ch| ch != '\n' && is_horizontal_whitespace ( ch) ) ;
564564 let invalid_infostring = self . first ( ) != '\n' ;
565565
566- let mut found = false ;
567566 let nl_fence_pattern = format ! ( "\n {:-<1$}" , "" , length_opening as usize ) ;
568567 if let Some ( closing) = self . as_str ( ) . find ( & nl_fence_pattern) {
569568 // candidate found
@@ -576,10 +575,7 @@ impl Cursor<'_> {
576575 // ----
577576 // combine those stuff into this frontmatter token such that it gets detected later.
578577 self . eat_until ( b'\n' ) ;
579- found = true ;
580- }
581-
582- if !found {
578+ } else {
583579 // recovery strategy: a closing statement might have preceding whitespace/newline
584580 // but not have enough dashes to properly close. In this case, we eat until there,
585581 // and report a mismatch in the parser.
@@ -656,23 +652,25 @@ impl Cursor<'_> {
656652 } ;
657653
658654 let mut depth = 1usize ;
659- while let Some ( c) = self . bump ( ) {
655+ while let Some ( c) = self . eat_past_either ( b'/' , b'*' ) {
660656 match c {
661- '/' if self . first ( ) == '*' => {
662- self . bump ( ) ;
663- depth += 1 ;
657+ b'/' => {
658+ if self . bump_if ( '*' ) {
659+ depth += 1 ;
660+ }
664661 }
665- '*' if self . first ( ) == '/' => {
666- self . bump ( ) ;
667- depth -= 1 ;
668- if depth == 0 {
669- // This block comment is closed, so for a construction like "/* */ */"
670- // there will be a successfully parsed block comment "/* */"
671- // and " */" will be processed separately.
672- break ;
662+ b'*' => {
663+ if self . bump_if ( '/' ) {
664+ depth -= 1 ;
665+ if depth == 0 {
666+ // This block comment is closed, so for a construction like "/* */ */"
667+ // there will be a successfully parsed block comment "/* */"
668+ // and " */" will be processed separately.
669+ break ;
670+ }
673671 }
674672 }
675- _ => ( ) ,
673+ _ => unreachable ! ( ) ,
676674 }
677675 }
678676
@@ -935,19 +933,15 @@ impl Cursor<'_> {
935933 /// if string is terminated.
936934 fn double_quoted_string ( & mut self ) -> bool {
937935 debug_assert ! ( self . prev( ) == '"' ) ;
938- while let Some ( c) = self . bump ( ) {
936+ while let Some ( c) = self . eat_past_either ( b'"' , b'\\' ) {
939937 match c {
940- '"' => {
938+ b '"' => {
941939 return true ;
942940 }
943- '\\' if self . first ( ) == '\\' || self . first ( ) == '"' => {
944- // Bump again to skip escaped character.
945- self . bump ( ) ;
946- }
947- _ => ( ) ,
941+ b'\\' => _ = self . bump_if_either ( '\\' , '"' ) ,
942+ _ => unreachable ! ( ) ,
948943 }
949944 }
950- // End of file reached.
951945 false
952946 }
953947
@@ -963,9 +957,8 @@ impl Cursor<'_> {
963957 debug_assert ! ( self . prev( ) != '#' ) ;
964958
965959 let mut n_start_hashes: u32 = 0 ;
966- while self . first ( ) == '#' {
960+ while self . bump_if ( '#' ) {
967961 n_start_hashes += 1 ;
968- self . bump ( ) ;
969962 }
970963
971964 if self . first ( ) != '"' {
@@ -1025,9 +1018,8 @@ impl Cursor<'_> {
10251018
10261019 // Count opening '#' symbols.
10271020 let mut eaten = 0 ;
1028- while self . first ( ) == '#' {
1021+ while self . bump_if ( '#' ) {
10291022 eaten += 1 ;
1030- self . bump ( ) ;
10311023 }
10321024 let n_start_hashes = eaten;
10331025
@@ -1043,9 +1035,7 @@ impl Cursor<'_> {
10431035 // Skip the string contents and on each '#' character met, check if this is
10441036 // a raw string termination.
10451037 loop {
1046- self . eat_until ( b'"' ) ;
1047-
1048- if self . is_eof ( ) {
1038+ if !self . eat_until ( b'"' ) {
10491039 return Err ( RawStrError :: NoTerminator {
10501040 expected : n_start_hashes,
10511041 found : max_hashes,
@@ -1117,9 +1107,7 @@ impl Cursor<'_> {
11171107 /// and returns false otherwise.
11181108 fn eat_float_exponent ( & mut self ) -> bool {
11191109 debug_assert ! ( self . prev( ) == 'e' || self . prev( ) == 'E' ) ;
1120- if self . first ( ) == '-' || self . first ( ) == '+' {
1121- self . bump ( ) ;
1122- }
1110+ self . bump_if_either ( '-' , '+' ) ;
11231111 self . eat_decimal_digits ( )
11241112 }
11251113
0 commit comments