Skip to content

Commit

Permalink
chore: remove unless change (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Mar 12, 2024
1 parent 868f30e commit b9901b2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/sourceview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<'a> Iterator for Lines<'a> {
pub struct SourceView<'a> {
source: Cow<'a, str>,
processed_until: AtomicUsize,
lines: Mutex<Vec<(*const u8, usize)>>,
lines: Mutex<Vec<&'static str>>,
}

impl<'a> Clone for SourceView<'a> {
Expand All @@ -163,11 +163,6 @@ impl<'a> fmt::Debug for SourceView<'a> {
}
}

unsafe fn make_str<'a>(tup: (*const u8, usize)) -> &'a str {
let (data, len) = tup;
str::from_utf8_unchecked(slice::from_raw_parts(data, len))
}

impl<'a> SourceView<'a> {
/// Creates an optimized view of a given source.
pub fn new(source: &'a str) -> SourceView<'a> {
Expand All @@ -193,7 +188,7 @@ impl<'a> SourceView<'a> {
{
let lines = self.lines.lock().unwrap();
if idx < lines.len() {
return Some(unsafe { make_str(lines[idx]) });
return Some(lines[idx]);
}
}

Expand Down Expand Up @@ -221,9 +216,12 @@ impl<'a> SourceView<'a> {
done = true;
rest
};
lines.push((rv.as_ptr(), rv.len()));

lines.push(unsafe {
str::from_utf8_unchecked(slice::from_raw_parts(rv.as_ptr(), rv.len()))
});
if let Some(&line) = lines.get(idx) {
return Some(unsafe { make_str(line) });
return Some(line);
}
}

Expand Down Expand Up @@ -370,4 +368,9 @@ fn test_minified_source_view() {
assert_eq!(view.get_line(2), Some("c"));
assert_eq!(view.get_line(3), Some(""));
assert_eq!(view.get_line(4), None);

fn is_send<T: Send>() {}
fn is_sync<T: Sync>() {}
is_send::<SourceView<'static>>();
is_sync::<SourceView<'static>>();
}

0 comments on commit b9901b2

Please sign in to comment.