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,7 +26,7 @@ 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 ! {
@@ -39,11 +35,10 @@ cfg_match! {
39
35
src: & str ,
40
36
lines: & mut Vec <RelativeBytePos >,
41
37
multi_byte_chars: & mut Vec <MultiByteChar >,
42
- non_narrow_chars: & mut Vec <NonNarrowChar >,
43
38
) {
44
39
if is_x86_feature_detected!( "sse2" ) {
45
40
unsafe {
46
- analyze_source_file_sse2( src, lines, multi_byte_chars, non_narrow_chars ) ;
41
+ analyze_source_file_sse2( src, lines, multi_byte_chars) ;
47
42
}
48
43
} else {
49
44
analyze_source_file_generic(
@@ -52,7 +47,6 @@ cfg_match! {
52
47
RelativeBytePos :: from_u32( 0 ) ,
53
48
lines,
54
49
multi_byte_chars,
55
- non_narrow_chars,
56
50
) ;
57
51
}
58
52
}
@@ -66,7 +60,6 @@ cfg_match! {
66
60
src: & str ,
67
61
lines: & mut Vec <RelativeBytePos >,
68
62
multi_byte_chars: & mut Vec <MultiByteChar >,
69
- non_narrow_chars: & mut Vec <NonNarrowChar >,
70
63
) {
71
64
#[ cfg( target_arch = "x86" ) ]
72
65
use std:: arch:: x86:: * ;
@@ -159,7 +152,6 @@ cfg_match! {
159
152
RelativeBytePos :: from_usize( scan_start) ,
160
153
lines,
161
154
multi_byte_chars,
162
- non_narrow_chars,
163
155
) ;
164
156
}
165
157
@@ -172,7 +164,6 @@ cfg_match! {
172
164
RelativeBytePos :: from_usize( tail_start) ,
173
165
lines,
174
166
multi_byte_chars,
175
- non_narrow_chars,
176
167
) ;
177
168
}
178
169
}
@@ -183,15 +174,13 @@ cfg_match! {
183
174
src: & str ,
184
175
lines: & mut Vec <RelativeBytePos >,
185
176
multi_byte_chars: & mut Vec <MultiByteChar >,
186
- non_narrow_chars: & mut Vec <NonNarrowChar >,
187
177
) {
188
178
analyze_source_file_generic(
189
179
src,
190
180
src. len( ) ,
191
181
RelativeBytePos :: from_u32( 0 ) ,
192
182
lines,
193
183
multi_byte_chars,
194
- non_narrow_chars,
195
184
) ;
196
185
}
197
186
}
@@ -205,7 +194,6 @@ fn analyze_source_file_generic(
205
194
output_offset : RelativeBytePos ,
206
195
lines : & mut Vec < RelativeBytePos > ,
207
196
multi_byte_chars : & mut Vec < MultiByteChar > ,
208
- non_narrow_chars : & mut Vec < NonNarrowChar > ,
209
197
) -> usize {
210
198
assert ! ( src. len( ) >= scan_len) ;
211
199
let mut i = 0 ;
@@ -227,16 +215,8 @@ fn analyze_source_file_generic(
227
215
228
216
let pos = RelativeBytePos :: from_usize ( i) + output_offset;
229
217
230
- match byte {
231
- b'\n' => {
232
- lines. push ( pos + RelativeBytePos ( 1 ) ) ;
233
- }
234
- b'\t' => {
235
- non_narrow_chars. push ( NonNarrowChar :: Tab ( pos) ) ;
236
- }
237
- _ => {
238
- non_narrow_chars. push ( NonNarrowChar :: ZeroWidth ( pos) ) ;
239
- }
218
+ if let b'\n' = byte {
219
+ lines. push ( pos + RelativeBytePos ( 1 ) ) ;
240
220
}
241
221
} else if byte >= 127 {
242
222
// The slow path:
@@ -252,14 +232,6 @@ fn analyze_source_file_generic(
252
232
let mbc = MultiByteChar { pos, bytes : char_len as u8 } ;
253
233
multi_byte_chars. push ( mbc) ;
254
234
}
255
-
256
- // Assume control characters are zero width.
257
- // FIXME: How can we decide between `width` and `width_cjk`?
258
- let char_width = UnicodeWidthChar :: width ( c) . unwrap_or ( 0 ) ;
259
-
260
- if char_width != 1 {
261
- non_narrow_chars. push ( NonNarrowChar :: new ( pos, char_width) ) ;
262
- }
263
235
}
264
236
265
237
i += char_len;
0 commit comments