diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-10 19:06:46 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-10 19:06:46 +0200 |
| commit | 63cfcbe7a7745b276de58ec92e0141b958c44feb (patch) | |
| tree | 990e33a83756e27187033579ee2f85d5c79169d5 /src/sheet/cell.rs | |
| parent | b747ca8af52129876b577a4f20f7105a05c6b002 (diff) | |
use unsafe blocks instead of mutexes
Diffstat (limited to 'src/sheet/cell.rs')
| -rw-r--r-- | src/sheet/cell.rs | 38 |
1 files changed, 10 insertions, 28 deletions
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<Self> { 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<Self> { @@ -157,16 +155,8 @@ impl CellRef { } pub fn end(&self) -> Option<Self> { - 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<Self> { @@ -174,16 +164,8 @@ impl CellRef { } pub fn bottom(&self) -> Option<Self> { - 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))? } } |