@@ -142,7 +142,7 @@ impl<'a> Iterator for Lines<'a> {
142142pub struct SourceView < ' a > {
143143 source : Cow < ' a , str > ,
144144 processed_until : AtomicUsize ,
145- lines : Mutex < Vec < ( * const u8 , usize ) > > ,
145+ lines : Mutex < Vec < & ' static str > > ,
146146}
147147
148148impl < ' a > Clone for SourceView < ' a > {
@@ -163,11 +163,6 @@ impl<'a> fmt::Debug for SourceView<'a> {
163163 }
164164}
165165
166- unsafe fn make_str < ' a > ( tup : ( * const u8 , usize ) ) -> & ' a str {
167- let ( data, len) = tup;
168- str:: from_utf8_unchecked ( slice:: from_raw_parts ( data, len) )
169- }
170-
171166impl < ' a > SourceView < ' a > {
172167 /// Creates an optimized view of a given source.
173168 pub fn new ( source : & ' a str ) -> SourceView < ' a > {
@@ -193,7 +188,7 @@ impl<'a> SourceView<'a> {
193188 {
194189 let lines = self . lines . lock ( ) . unwrap ( ) ;
195190 if idx < lines. len ( ) {
196- return Some ( unsafe { make_str ( lines[ idx] ) } ) ;
191+ return Some ( lines[ idx] ) ;
197192 }
198193 }
199194
@@ -221,9 +216,12 @@ impl<'a> SourceView<'a> {
221216 done = true ;
222217 rest
223218 } ;
224- lines. push ( ( rv. as_ptr ( ) , rv. len ( ) ) ) ;
219+
220+ lines. push ( unsafe {
221+ str:: from_utf8_unchecked ( slice:: from_raw_parts ( rv. as_ptr ( ) , rv. len ( ) ) )
222+ } ) ;
225223 if let Some ( & line) = lines. get ( idx) {
226- return Some ( unsafe { make_str ( line) } ) ;
224+ return Some ( line) ;
227225 }
228226 }
229227
@@ -370,4 +368,9 @@ fn test_minified_source_view() {
370368 assert_eq ! ( view. get_line( 2 ) , Some ( "c" ) ) ;
371369 assert_eq ! ( view. get_line( 3 ) , Some ( "" ) ) ;
372370 assert_eq ! ( view. get_line( 4 ) , None ) ;
371+
372+ fn is_send < T : Send > ( ) { }
373+ fn is_sync < T : Sync > ( ) { }
374+ is_send :: < SourceView < ' static > > ( ) ;
375+ is_sync :: < SourceView < ' static > > ( ) ;
373376}
0 commit comments