11use crate :: ignore;
2- use bstr:: { BStr , BString , ByteSlice } ;
2+ use bstr:: { BString , ByteSlice } ;
33
44pub struct Iter < ' a > {
5- cursor : & ' a BStr ,
5+ lines : bstr :: Lines < ' a > ,
66 line_no : usize ,
77}
88
99impl < ' a > Iter < ' a > {
1010 pub fn new ( buf : & ' a [ u8 ] ) -> Self {
1111 Iter {
12- cursor : buf. as_bstr ( ) ,
12+ lines : buf. lines ( ) ,
1313 line_no : 0 ,
1414 }
1515 }
@@ -19,16 +19,9 @@ impl<'a> Iterator for Iter<'a> {
1919 type Item = ( BString , ignore:: pattern:: Mode , usize ) ;
2020
2121 fn next ( & mut self ) -> Option < Self :: Item > {
22- if self . cursor . is_empty ( ) {
23- return None ;
24- }
25- let mut lines = self . cursor . lines_with_terminator ( ) ;
2622 let mut res = None ;
27- let mut offset = 0 ; // TODO: prefer `lines()` with `into_bytes()` instead.
28- for mut line in lines. by_ref ( ) {
23+ for mut line in self . lines . by_ref ( ) {
2924 self . line_no += 1 ;
30- offset += line. len ( ) ;
31- line = trim_newline ( line) ;
3225 let mut mode = ignore:: pattern:: Mode :: empty ( ) ;
3326 if line. is_empty ( ) {
3427 continue ;
@@ -58,22 +51,10 @@ impl<'a> Iterator for Iter<'a> {
5851 res = Some ( ( line, mode, self . line_no ) ) ;
5952 break ;
6053 }
61- self . cursor = & self . cursor [ offset..] ;
6254 res
6355 }
6456}
6557
66- #[ inline]
67- fn trim_newline ( mut line : & [ u8 ] ) -> & [ u8 ] {
68- if line. last_byte ( ) == Some ( b'\n' ) {
69- line = & line[ ..line. len ( ) - 1 ] ;
70- if line. last_byte ( ) == Some ( b'\r' ) {
71- line = & line[ ..line. len ( ) - 1 ] ;
72- }
73- }
74- line
75- }
76-
7758/// We always copy just because that's ultimately needed anyway, not because we always have to.
7859fn truncate_non_escaped_trailing_spaces ( buf : & [ u8 ] ) -> BString {
7960 match buf. rfind_not_byteset ( br"\ " ) {
0 commit comments