1
1
use super :: * ;
2
- use unicode_width:: UnicodeWidthChar ;
3
2
4
3
#[ cfg( test) ]
5
4
mod tests;
@@ -9,15 +8,12 @@ mod tests;
9
8
///
10
9
/// This function will use an SSE2 enhanced implementation if hardware support
11
10
/// is detected at runtime.
12
- pub fn analyze_source_file (
13
- src : & str ,
14
- ) -> ( Vec < RelativeBytePos > , Vec < MultiByteChar > , Vec < NonNarrowChar > ) {
11
+ pub fn analyze_source_file ( src : & str ) -> ( Vec < RelativeBytePos > , Vec < MultiByteChar > ) {
15
12
let mut lines = vec ! [ RelativeBytePos :: from_u32( 0 ) ] ;
16
13
let mut multi_byte_chars = vec ! [ ] ;
17
- let mut non_narrow_chars = vec ! [ ] ;
18
14
19
15
// Calls the right implementation, depending on hardware support available.
20
- analyze_source_file_dispatch ( src, & mut lines, & mut multi_byte_chars, & mut non_narrow_chars ) ;
16
+ analyze_source_file_dispatch ( src, & mut lines, & mut multi_byte_chars) ;
21
17
22
18
// The code above optimistically registers a new line *after* each \n
23
19
// it encounters. If that point is already outside the source_file, remove
@@ -30,29 +26,26 @@ pub fn analyze_source_file(
30
26
}
31
27
}
32
28
33
- ( lines, multi_byte_chars, non_narrow_chars )
29
+ ( lines, multi_byte_chars)
34
30
}
35
31
36
32
cfg_match ! {
37
33
cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) => {
38
34
fn analyze_source_file_dispatch( src: & str ,
39
35
lines: & mut Vec <RelativeBytePos >,
40
- multi_byte_chars: & mut Vec <MultiByteChar >,
41
- non_narrow_chars: & mut Vec <NonNarrowChar >) {
36
+ multi_byte_chars: & mut Vec <MultiByteChar >) {
42
37
if is_x86_feature_detected!( "sse2" ) {
43
38
unsafe {
44
39
analyze_source_file_sse2( src,
45
40
lines,
46
- multi_byte_chars,
47
- non_narrow_chars) ;
41
+ multi_byte_chars) ;
48
42
}
49
43
} else {
50
44
analyze_source_file_generic( src,
51
45
src. len( ) ,
52
46
RelativeBytePos :: from_u32( 0 ) ,
53
47
lines,
54
- multi_byte_chars,
55
- non_narrow_chars) ;
48
+ multi_byte_chars) ;
56
49
57
50
}
58
51
}
@@ -64,8 +57,7 @@ cfg_match! {
64
57
#[ target_feature( enable = "sse2" ) ]
65
58
unsafe fn analyze_source_file_sse2( src: & str ,
66
59
lines: & mut Vec <RelativeBytePos >,
67
- multi_byte_chars: & mut Vec <MultiByteChar >,
68
- non_narrow_chars: & mut Vec <NonNarrowChar >) {
60
+ multi_byte_chars: & mut Vec <MultiByteChar >) {
69
61
#[ cfg( target_arch = "x86" ) ]
70
62
use std:: arch:: x86:: * ;
71
63
#[ cfg( target_arch = "x86_64" ) ]
@@ -157,7 +149,6 @@ cfg_match! {
157
149
RelativeBytePos :: from_usize( scan_start) ,
158
150
lines,
159
151
multi_byte_chars,
160
- non_narrow_chars
161
152
) ;
162
153
}
163
154
@@ -168,23 +159,20 @@ cfg_match! {
168
159
src. len( ) - tail_start,
169
160
RelativeBytePos :: from_usize( tail_start) ,
170
161
lines,
171
- multi_byte_chars,
172
- non_narrow_chars) ;
162
+ multi_byte_chars) ;
173
163
}
174
164
}
175
165
}
176
166
_ => {
177
167
// The target (or compiler version) does not support SSE2 ...
178
168
fn analyze_source_file_dispatch( src: & str ,
179
169
lines: & mut Vec <RelativeBytePos >,
180
- multi_byte_chars: & mut Vec <MultiByteChar >,
181
- non_narrow_chars: & mut Vec <NonNarrowChar >) {
170
+ multi_byte_chars: & mut Vec <MultiByteChar >) {
182
171
analyze_source_file_generic( src,
183
172
src. len( ) ,
184
173
RelativeBytePos :: from_u32( 0 ) ,
185
174
lines,
186
- multi_byte_chars,
187
- non_narrow_chars) ;
175
+ multi_byte_chars) ;
188
176
}
189
177
}
190
178
}
@@ -198,7 +186,6 @@ fn analyze_source_file_generic(
198
186
output_offset : RelativeBytePos ,
199
187
lines : & mut Vec < RelativeBytePos > ,
200
188
multi_byte_chars : & mut Vec < MultiByteChar > ,
201
- non_narrow_chars : & mut Vec < NonNarrowChar > ,
202
189
) -> usize {
203
190
assert ! ( src. len( ) >= scan_len) ;
204
191
let mut i = 0 ;
@@ -220,16 +207,8 @@ fn analyze_source_file_generic(
220
207
221
208
let pos = RelativeBytePos :: from_usize ( i) + output_offset;
222
209
223
- match byte {
224
- b'\n' => {
225
- lines. push ( pos + RelativeBytePos ( 1 ) ) ;
226
- }
227
- b'\t' => {
228
- non_narrow_chars. push ( NonNarrowChar :: Tab ( pos) ) ;
229
- }
230
- _ => {
231
- non_narrow_chars. push ( NonNarrowChar :: ZeroWidth ( pos) ) ;
232
- }
210
+ if let b'\n' = byte {
211
+ lines. push ( pos + RelativeBytePos ( 1 ) ) ;
233
212
}
234
213
} else if byte >= 127 {
235
214
// The slow path:
@@ -245,14 +224,6 @@ fn analyze_source_file_generic(
245
224
let mbc = MultiByteChar { pos, bytes : char_len as u8 } ;
246
225
multi_byte_chars. push ( mbc) ;
247
226
}
248
-
249
- // Assume control characters are zero width.
250
- // FIXME: How can we decide between `width` and `width_cjk`?
251
- let char_width = UnicodeWidthChar :: width ( c) . unwrap_or ( 0 ) ;
252
-
253
- if char_width != 1 {
254
- non_narrow_chars. push ( NonNarrowChar :: new ( pos, char_width) ) ;
255
- }
256
227
}
257
228
258
229
i += char_len;
0 commit comments