11use super :: * ;
2- use unicode_width:: UnicodeWidthChar ;
32
43#[ cfg( test) ]
54mod tests;
@@ -9,15 +8,12 @@ mod tests;
98///
109/// This function will use an SSE2 enhanced implementation if hardware support
1110/// 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 > ) {
1512 let mut lines = vec ! [ RelativeBytePos :: from_u32( 0 ) ] ;
1613 let mut multi_byte_chars = vec ! [ ] ;
17- let mut non_narrow_chars = vec ! [ ] ;
1814
1915 // 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) ;
2117
2218 // The code above optimistically registers a new line *after* each \n
2319 // it encounters. If that point is already outside the source_file, remove
@@ -30,29 +26,26 @@ pub fn analyze_source_file(
3026 }
3127 }
3228
33- ( lines, multi_byte_chars, non_narrow_chars )
29+ ( lines, multi_byte_chars)
3430}
3531
3632cfg_match ! {
3733 cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) => {
3834 fn analyze_source_file_dispatch( src: & str ,
3935 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 >) {
4237 if is_x86_feature_detected!( "sse2" ) {
4338 unsafe {
4439 analyze_source_file_sse2( src,
4540 lines,
46- multi_byte_chars,
47- non_narrow_chars) ;
41+ multi_byte_chars) ;
4842 }
4943 } else {
5044 analyze_source_file_generic( src,
5145 src. len( ) ,
5246 RelativeBytePos :: from_u32( 0 ) ,
5347 lines,
54- multi_byte_chars,
55- non_narrow_chars) ;
48+ multi_byte_chars) ;
5649
5750 }
5851 }
@@ -64,8 +57,7 @@ cfg_match! {
6457 #[ target_feature( enable = "sse2" ) ]
6558 unsafe fn analyze_source_file_sse2( src: & str ,
6659 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 >) {
6961 #[ cfg( target_arch = "x86" ) ]
7062 use std:: arch:: x86:: * ;
7163 #[ cfg( target_arch = "x86_64" ) ]
@@ -157,7 +149,6 @@ cfg_match! {
157149 RelativeBytePos :: from_usize( scan_start) ,
158150 lines,
159151 multi_byte_chars,
160- non_narrow_chars
161152 ) ;
162153 }
163154
@@ -168,23 +159,20 @@ cfg_match! {
168159 src. len( ) - tail_start,
169160 RelativeBytePos :: from_usize( tail_start) ,
170161 lines,
171- multi_byte_chars,
172- non_narrow_chars) ;
162+ multi_byte_chars) ;
173163 }
174164 }
175165 }
176166 _ => {
177167 // The target (or compiler version) does not support SSE2 ...
178168 fn analyze_source_file_dispatch( src: & str ,
179169 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 >) {
182171 analyze_source_file_generic( src,
183172 src. len( ) ,
184173 RelativeBytePos :: from_u32( 0 ) ,
185174 lines,
186- multi_byte_chars,
187- non_narrow_chars) ;
175+ multi_byte_chars) ;
188176 }
189177 }
190178}
@@ -198,7 +186,6 @@ fn analyze_source_file_generic(
198186 output_offset : RelativeBytePos ,
199187 lines : & mut Vec < RelativeBytePos > ,
200188 multi_byte_chars : & mut Vec < MultiByteChar > ,
201- non_narrow_chars : & mut Vec < NonNarrowChar > ,
202189) -> usize {
203190 assert ! ( src. len( ) >= scan_len) ;
204191 let mut i = 0 ;
@@ -220,16 +207,8 @@ fn analyze_source_file_generic(
220207
221208 let pos = RelativeBytePos :: from_usize ( i) + output_offset;
222209
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 ) ) ;
233212 }
234213 } else if byte >= 127 {
235214 // The slow path:
@@ -245,14 +224,6 @@ fn analyze_source_file_generic(
245224 let mbc = MultiByteChar { pos, bytes : char_len as u8 } ;
246225 multi_byte_chars. push ( mbc) ;
247226 }
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- }
256227 }
257228
258229 i += char_len;
0 commit comments