@@ -35,25 +35,25 @@ pub fn analyze_source_file(
35
35
36
36
cfg_match ! {
37
37
cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) => {
38
- fn analyze_source_file_dispatch( src: & str ,
39
- lines: & mut Vec <RelativeBytePos >,
40
- multi_byte_chars: & mut Vec <MultiByteChar >,
41
- non_narrow_chars: & mut Vec <NonNarrowChar >) {
38
+ fn analyze_source_file_dispatch(
39
+ src: & str ,
40
+ lines: & mut Vec <RelativeBytePos >,
41
+ multi_byte_chars: & mut Vec <MultiByteChar >,
42
+ non_narrow_chars: & mut Vec <NonNarrowChar >,
43
+ ) {
42
44
if is_x86_feature_detected!( "sse2" ) {
43
45
unsafe {
44
- analyze_source_file_sse2( src,
45
- lines,
46
- multi_byte_chars,
47
- non_narrow_chars) ;
46
+ analyze_source_file_sse2( src, lines, multi_byte_chars, non_narrow_chars) ;
48
47
}
49
48
} else {
50
- analyze_source_file_generic( src,
51
- src. len( ) ,
52
- RelativeBytePos :: from_u32( 0 ) ,
53
- lines,
54
- multi_byte_chars,
55
- non_narrow_chars) ;
56
-
49
+ analyze_source_file_generic(
50
+ src,
51
+ src. len( ) ,
52
+ RelativeBytePos :: from_u32( 0 ) ,
53
+ lines,
54
+ multi_byte_chars,
55
+ non_narrow_chars,
56
+ ) ;
57
57
}
58
58
}
59
59
@@ -62,10 +62,12 @@ cfg_match! {
62
62
/// function falls back to the generic implementation. Otherwise it uses
63
63
/// SSE2 intrinsics to quickly find all newlines.
64
64
#[ target_feature( enable = "sse2" ) ]
65
- unsafe fn analyze_source_file_sse2( src: & str ,
66
- lines: & mut Vec <RelativeBytePos >,
67
- multi_byte_chars: & mut Vec <MultiByteChar >,
68
- non_narrow_chars: & mut Vec <NonNarrowChar >) {
65
+ unsafe fn analyze_source_file_sse2(
66
+ src: & str ,
67
+ lines: & mut Vec <RelativeBytePos >,
68
+ multi_byte_chars: & mut Vec <MultiByteChar >,
69
+ non_narrow_chars: & mut Vec <NonNarrowChar >,
70
+ ) {
69
71
#[ cfg( target_arch = "x86" ) ]
70
72
use std:: arch:: x86:: * ;
71
73
#[ cfg( target_arch = "x86_64" ) ]
@@ -83,7 +85,7 @@ cfg_match! {
83
85
// handled it.
84
86
let mut intra_chunk_offset = 0 ;
85
87
86
- for chunk_index in 0 .. chunk_count {
88
+ for chunk_index in 0 .. chunk_count {
87
89
let ptr = src_bytes. as_ptr( ) as * const __m128i;
88
90
// We don't know if the pointer is aligned to 16 bytes, so we
89
91
// use `loadu`, which supports unaligned loading.
@@ -126,7 +128,7 @@ cfg_match! {
126
128
127
129
if index >= CHUNK_SIZE as u32 {
128
130
// We have arrived at the end of the chunk.
129
- break
131
+ break ;
130
132
}
131
133
132
134
lines. push( RelativeBytePos ( index) + output_offset) ;
@@ -137,58 +139,63 @@ cfg_match! {
137
139
138
140
// We are done for this chunk. All control characters were
139
141
// newlines and we took care of those.
140
- continue
142
+ continue ;
141
143
} else {
142
144
// Some of the control characters are not newlines,
143
145
// fall through to the slow path below.
144
146
}
145
147
} else {
146
148
// No control characters, nothing to record for this chunk
147
- continue
149
+ continue ;
148
150
}
149
151
}
150
152
151
153
// The slow path.
152
154
// There are control chars in here, fallback to generic decoding.
153
155
let scan_start = chunk_index * CHUNK_SIZE + intra_chunk_offset;
154
156
intra_chunk_offset = analyze_source_file_generic(
155
- & src[ scan_start .. ] ,
157
+ & src[ scan_start.. ] ,
156
158
CHUNK_SIZE - intra_chunk_offset,
157
159
RelativeBytePos :: from_usize( scan_start) ,
158
160
lines,
159
161
multi_byte_chars,
160
- non_narrow_chars
162
+ non_narrow_chars,
161
163
) ;
162
164
}
163
165
164
166
// There might still be a tail left to analyze
165
167
let tail_start = chunk_count * CHUNK_SIZE + intra_chunk_offset;
166
168
if tail_start < src. len( ) {
167
- analyze_source_file_generic( & src[ tail_start ..] ,
168
- src. len( ) - tail_start,
169
- RelativeBytePos :: from_usize( tail_start) ,
170
- lines,
171
- multi_byte_chars,
172
- non_narrow_chars) ;
169
+ analyze_source_file_generic(
170
+ & src[ tail_start..] ,
171
+ src. len( ) - tail_start,
172
+ RelativeBytePos :: from_usize( tail_start) ,
173
+ lines,
174
+ multi_byte_chars,
175
+ non_narrow_chars,
176
+ ) ;
173
177
}
174
178
}
175
179
}
176
180
_ => {
177
181
// The target (or compiler version) does not support SSE2 ...
178
- fn analyze_source_file_dispatch( src: & str ,
179
- lines: & mut Vec <RelativeBytePos >,
180
- multi_byte_chars: & mut Vec <MultiByteChar >,
181
- non_narrow_chars: & mut Vec <NonNarrowChar >) {
182
- analyze_source_file_generic( src,
183
- src. len( ) ,
184
- RelativeBytePos :: from_u32( 0 ) ,
185
- lines,
186
- multi_byte_chars,
187
- non_narrow_chars) ;
182
+ fn analyze_source_file_dispatch(
183
+ src: & str ,
184
+ lines: & mut Vec <RelativeBytePos >,
185
+ multi_byte_chars: & mut Vec <MultiByteChar >,
186
+ non_narrow_chars: & mut Vec <NonNarrowChar >,
187
+ ) {
188
+ analyze_source_file_generic(
189
+ src,
190
+ src. len( ) ,
191
+ RelativeBytePos :: from_u32( 0 ) ,
192
+ lines,
193
+ multi_byte_chars,
194
+ non_narrow_chars,
195
+ ) ;
188
196
}
189
197
}
190
198
}
191
-
192
199
// `scan_len` determines the number of bytes in `src` to scan. Note that the
193
200
// function can read past `scan_len` if a multi-byte character start within the
194
201
// range but extends past it. The overflow is returned by the function.
0 commit comments