Skip to content

Commit

Permalink
Remove owning-ref dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Mar 27, 2024
1 parent 85259cc commit 6270b34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
1 change: 0 additions & 1 deletion cursive-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ repository = "gyscos/cursive"
enum-map = "2.0"
enumset = "1.0.4"
log = "0.4"
owning_ref = "0.4"
unicode-segmentation = "1"
unicode-width = "0.1"
xi-unicode = "0.3"
Expand Down
24 changes: 8 additions & 16 deletions cursive-core/src/views/text_view.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use parking_lot::Mutex;
use std::ops::Deref;
use std::sync::Arc;
use std::sync::{Mutex, MutexGuard};

use owning_ref::{ArcRef, OwningHandle};
use unicode_width::UnicodeWidthStr;

use crate::align::*;
Expand Down Expand Up @@ -65,7 +64,6 @@ impl TextContent {
///
/// This keeps the content locked. Do not store this!
pub struct TextContentRef {
_handle: OwningHandle<ArcRef<Mutex<TextContentInner>>, MutexGuard<'static, TextContentInner>>,
// We also need to keep a copy of Arc so `deref` can return
// a reference to the `StyledString`
data: Arc<StyledString>,
Expand Down Expand Up @@ -123,7 +121,7 @@ impl TextContent {
where
F: FnOnce(&mut TextContentInner) -> O,
{
let mut content = self.content.lock().unwrap();
let mut content = self.content.lock();

let out = f(&mut content);

Expand All @@ -150,14 +148,8 @@ struct TextContentInner {
impl TextContentInner {
/// From a shareable content (Arc + Mutex), return a
fn get_content(content: &Arc<Mutex<TextContentInner>>) -> TextContentRef {
let arc_ref: ArcRef<Mutex<TextContentInner>> = ArcRef::new(Arc::clone(content));

let _handle =
OwningHandle::new_with_fn(arc_ref, |mutex| unsafe { (*mutex).lock().unwrap() });

let data = Arc::clone(&_handle.content_value);

TextContentRef { _handle, data }
let data = Arc::clone(&content.lock().content_value);
TextContentRef { data }
}

fn is_cache_valid(&self, size: Vec2) -> bool {
Expand Down Expand Up @@ -360,7 +352,7 @@ impl TextView {
fn compute_rows(&mut self, size: Vec2) {
let size = if self.wrap { size } else { Vec2::max_value() };

let mut content = self.content.content.lock().unwrap();
let mut content = self.content.content.lock();
if content.is_cache_valid(size) {
return;
}
Expand Down Expand Up @@ -394,7 +386,7 @@ impl View for TextView {
let offset = self.align.v.get_offset(h, printer.size.y);
let printer = &printer.offset((0, offset));

let content = self.content.content.lock().unwrap();
let content = self.content.content.lock();

printer.with_style(self.style, |printer| {
for (y, row) in self
Expand All @@ -418,7 +410,7 @@ impl View for TextView {
}

fn needs_relayout(&self) -> bool {
let content = self.content.content.lock().unwrap();
let content = self.content.content.lock();
content.size_cache.is_none()
}

Expand All @@ -436,7 +428,7 @@ impl View for TextView {
let my_size = Vec2::new(self.width.unwrap_or(0), self.rows.len());

// Build a fresh cache.
let mut content = self.content.content.lock().unwrap();
let mut content = self.content.content.lock();
content.size_cache = Some(SizeCache::build(my_size, size));
}
}
Expand Down

0 comments on commit 6270b34

Please sign in to comment.