1
1
use crate :: ignore;
2
- use bstr:: { BStr , BString , ByteSlice } ;
2
+ use bstr:: { BString , ByteSlice } ;
3
3
4
4
pub struct Iter < ' a > {
5
- cursor : & ' a BStr ,
5
+ lines : bstr :: Lines < ' a > ,
6
6
line_no : usize ,
7
7
}
8
8
9
9
impl < ' a > Iter < ' a > {
10
10
pub fn new ( buf : & ' a [ u8 ] ) -> Self {
11
11
Iter {
12
- cursor : buf. as_bstr ( ) ,
12
+ lines : buf. lines ( ) ,
13
13
line_no : 0 ,
14
14
}
15
15
}
@@ -19,16 +19,9 @@ impl<'a> Iterator for Iter<'a> {
19
19
type Item = ( BString , ignore:: pattern:: Mode , usize ) ;
20
20
21
21
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 ( ) ;
26
22
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 ( ) {
29
24
self . line_no += 1 ;
30
- offset += line. len ( ) ;
31
- line = trim_newline ( line) ;
32
25
let mut mode = ignore:: pattern:: Mode :: empty ( ) ;
33
26
if line. is_empty ( ) {
34
27
continue ;
@@ -58,22 +51,10 @@ impl<'a> Iterator for Iter<'a> {
58
51
res = Some ( ( line, mode, self . line_no ) ) ;
59
52
break ;
60
53
}
61
- self . cursor = & self . cursor [ offset..] ;
62
54
res
63
55
}
64
56
}
65
57
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
-
77
58
/// We always copy just because that's ultimately needed anyway, not because we always have to.
78
59
fn truncate_non_escaped_trailing_spaces ( buf : & [ u8 ] ) -> BString {
79
60
match buf. rfind_not_byteset ( br"\ " ) {
0 commit comments