From 63cfcbe7a7745b276de58ec92e0141b958c44feb Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 10 Aug 2024 19:06:46 +0200 Subject: use unsafe blocks instead of mutexes --- src/sheet/cell.rs | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'src/sheet/cell.rs') diff --git a/src/sheet/cell.rs b/src/sheet/cell.rs index b46b7d4..d723732 100644 --- a/src/sheet/cell.rs +++ b/src/sheet/cell.rs @@ -98,14 +98,14 @@ impl CellRef { sheet_id, row, column, - value: cell + value: cell, } } pub fn fetch_new(sheet_id: SheetId, row: usize, column: usize) -> Option { Register::get(sheet_id) .map(|sheet| { - sheet.read().unwrap().get_cell(row, column).map(|cell| Self { + sheet.get_cell(row, column).map(|cell| Self { sheet_id, row, column, @@ -120,12 +120,10 @@ impl CellRef { } pub fn set_value(&mut self, cell: Cell) { - self.value = cell.clone(); - Register::get(self.sheet_id) - .unwrap() - .write() - .unwrap() - .set_cell(self.row, self.column, cell); + if let Some(sheet) = Register::get(self.sheet_id) { + self.value = cell.clone(); + sheet.set_cell(self.row, self.column, cell); + } } pub fn left(&self) -> Option { @@ -157,16 +155,8 @@ impl CellRef { } pub fn end(&self) -> Option { - Self::fetch_new( - self.sheet_id, - self.row, - Register::get(self.sheet_id) - .unwrap() - .read() - .unwrap() - .width() - - 1, - ) + Register::get(self.sheet_id) + .map(|sheet| Self::fetch_new(self.sheet_id, self.row, sheet.width() - 1))? } pub fn top(&self) -> Option { @@ -174,16 +164,8 @@ impl CellRef { } pub fn bottom(&self) -> Option { - Self::fetch_new( - self.sheet_id, - Register::get(self.sheet_id) - .unwrap() - .read() - .unwrap() - .height() - - 1, - self.column, - ) + Register::get(self.sheet_id) + .map(|sheet| Self::fetch_new(self.sheet_id, sheet.height() - 1, self.column))? } } -- cgit v1.2.3-70-g09d2