Skip to content

Commit

Permalink
Avoid option dance in WritablePage by taking additonal reference coun…
Browse files Browse the repository at this point in the history
…t traffic in its Drop impl.
  • Loading branch information
adamreichold authored and cberner committed May 11, 2024
1 parent 5a6af86 commit 94e90d5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/tree_store/page_store/cached_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,26 @@ impl CachePriority {
pub(super) struct WritablePage {
buffer: Arc<Mutex<PrioritizedWriteCache>>,
offset: u64,
data: Option<Arc<[u8]>>,
data: Arc<[u8]>,
priority: CachePriority,
}

impl WritablePage {
pub(super) fn mem(&self) -> &[u8] {
self.data.as_ref().unwrap()
&self.data
}

pub(super) fn mem_mut(&mut self) -> &mut [u8] {
Arc::get_mut(self.data.as_mut().unwrap()).unwrap()
Arc::get_mut(&mut self.data).unwrap()
}
}

impl Drop for WritablePage {
fn drop(&mut self) {
let data = self.data.take().unwrap();
self.buffer
.lock()
.unwrap()
.return_value(&self.offset, data, self.priority);
.return_value(&self.offset, self.data.clone(), self.priority);
}
}

Expand Down Expand Up @@ -487,7 +486,7 @@ impl PagedCachedFile {
Ok(WritablePage {
buffer: self.write_buffer.clone(),
offset,
data: Some(data),
data,
priority,
})
}
Expand Down

0 comments on commit 94e90d5

Please sign in to comment.