Skip to content

Commit b9901b2

Browse files
authored
chore: remove unless change (#82)
1 parent 868f30e commit b9901b2

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/sourceview.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a> Iterator for Lines<'a> {
142142
pub 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

148148
impl<'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-
171166
impl<'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

Comments
 (0)