@@ -974,32 +974,35 @@ impl BangType {
974974 /// - `chunk`: data read on current iteration and not yet consumed from reader
975975 #[ inline( always) ]
976976 fn parse < ' b > ( & self , buf : & [ u8 ] , chunk : & ' b [ u8 ] ) -> Option < ( & ' b [ u8 ] , usize ) > {
977- for i in memchr:: memchr_iter ( b'>' , chunk) {
978- match self {
979- // Need to read at least 6 symbols (`!---->`) for properly finished comment
980- // <!----> - XML comment
981- // 012345 - i
982- Self :: Comment if buf. len ( ) + i > 4 => {
983- if chunk[ ..i] . ends_with ( b"--" ) {
984- // We cannot strip last `--` from the buffer because we need it in case of
985- // check_comments enabled option. XML standard requires that comment
986- // will not end with `--->` sequence because this is a special case of
987- // `--` in the comment (https://www.w3.org/TR/xml11/#sec-comments)
988- return Some ( ( & chunk[ ..i] , i + 1 ) ) ; // +1 for `>`
989- }
990- // End sequence `-|->` was splitted at |
991- // buf --/ \-- chunk
992- if i == 1 && buf. ends_with ( b"-" ) && chunk[ 0 ] == b'-' {
993- return Some ( ( & chunk[ ..i] , i + 1 ) ) ; // +1 for `>`
994- }
995- // End sequence `--|>` was splitted at |
996- // buf --/ \-- chunk
997- if i == 0 && buf. ends_with ( b"--" ) {
998- return Some ( ( & [ ] , i + 1 ) ) ; // +1 for `>`
977+ match self {
978+ Self :: Comment => {
979+ for i in memchr:: memchr_iter ( b'>' , chunk) {
980+ // Need to read at least 6 symbols (`!---->`) for properly finished comment
981+ // <!----> - XML comment
982+ // 012345 - i
983+ if buf. len ( ) + i > 4 {
984+ if chunk[ ..i] . ends_with ( b"--" ) {
985+ // We cannot strip last `--` from the buffer because we need it in case of
986+ // check_comments enabled option. XML standard requires that comment
987+ // will not end with `--->` sequence because this is a special case of
988+ // `--` in the comment (https://www.w3.org/TR/xml11/#sec-comments)
989+ return Some ( ( & chunk[ ..i] , i + 1 ) ) ; // +1 for `>`
990+ }
991+ // End sequence `-|->` was splitted at |
992+ // buf --/ \-- chunk
993+ if i == 1 && buf. ends_with ( b"-" ) && chunk[ 0 ] == b'-' {
994+ return Some ( ( & chunk[ ..i] , i + 1 ) ) ; // +1 for `>`
995+ }
996+ // End sequence `--|>` was splitted at |
997+ // buf --/ \-- chunk
998+ if i == 0 && buf. ends_with ( b"--" ) {
999+ return Some ( ( & [ ] , i + 1 ) ) ; // +1 for `>`
1000+ }
9991001 }
10001002 }
1001- Self :: Comment => { }
1002- Self :: CData => {
1003+ }
1004+ Self :: CData => {
1005+ for i in memchr:: memchr_iter ( b'>' , chunk) {
10031006 if chunk[ ..i] . ends_with ( b"]]" ) {
10041007 return Some ( ( & chunk[ ..i] , i + 1 ) ) ; // +1 for `>`
10051008 }
@@ -1014,7 +1017,9 @@ impl BangType {
10141017 return Some ( ( & [ ] , i + 1 ) ) ; // +1 for `>`
10151018 }
10161019 }
1017- Self :: DocType => {
1020+ }
1021+ Self :: DocType => {
1022+ for i in memchr:: memchr_iter ( b'>' , chunk) {
10181023 let content = & chunk[ ..i] ;
10191024 let balance = memchr:: memchr2_iter ( b'<' , b'>' , content)
10201025 . map ( |p| if content[ p] == b'<' { 1i32 } else { -1 } )
0 commit comments