@@ -142,7 +142,7 @@ impl<'a> Iterator for Lines<'a> {
142
142
pub struct SourceView < ' a > {
143
143
source : Cow < ' a , str > ,
144
144
processed_until : AtomicUsize ,
145
- lines : Mutex < Vec < ( * const u8 , usize ) > > ,
145
+ lines : Mutex < Vec < & ' static str > > ,
146
146
}
147
147
148
148
impl < ' a > Clone for SourceView < ' a > {
@@ -163,11 +163,6 @@ impl<'a> fmt::Debug for SourceView<'a> {
163
163
}
164
164
}
165
165
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
-
171
166
impl < ' a > SourceView < ' a > {
172
167
/// Creates an optimized view of a given source.
173
168
pub fn new ( source : & ' a str ) -> SourceView < ' a > {
@@ -193,7 +188,7 @@ impl<'a> SourceView<'a> {
193
188
{
194
189
let lines = self . lines . lock ( ) . unwrap ( ) ;
195
190
if idx < lines. len ( ) {
196
- return Some ( unsafe { make_str ( lines[ idx] ) } ) ;
191
+ return Some ( lines[ idx] ) ;
197
192
}
198
193
}
199
194
@@ -221,9 +216,12 @@ impl<'a> SourceView<'a> {
221
216
done = true ;
222
217
rest
223
218
} ;
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
+ } ) ;
225
223
if let Some ( & line) = lines. get ( idx) {
226
- return Some ( unsafe { make_str ( line) } ) ;
224
+ return Some ( line) ;
227
225
}
228
226
}
229
227
@@ -370,4 +368,9 @@ fn test_minified_source_view() {
370
368
assert_eq ! ( view. get_line( 2 ) , Some ( "c" ) ) ;
371
369
assert_eq ! ( view. get_line( 3 ) , Some ( "" ) ) ;
372
370
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 > > ( ) ;
373
376
}
0 commit comments