Skip to content

Commit

Permalink
Remove get_mut_unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
danielSanchezQ committed Sep 2, 2022
1 parent 2ff6d0e commit 8b19199
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 60 deletions.
20 changes: 0 additions & 20 deletions src/imp_pl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,6 @@ impl<T> OnceCell<T> {
}
}

/// Get a mutable reference to the underlying value, without checking if the cell
/// is initialized.
///
/// # Safety
///
/// Caller must ensure that the cell is in initialized state, and that
/// the contents are acquired by (synchronized to) this thread.
pub(crate) unsafe fn get_mut_unchecked(&mut self) -> &mut T {
debug_assert!(self.is_initialized());
let slot: &mut Option<T> = &mut *self.value.get();
match slot {
Some(value) => value,
// This unsafe does improve performance, see `examples/bench`.
None => {
debug_assert!(false);
hint::unreachable_unchecked()
}
}
}

/// Gets the mutable reference to the underlying value.
/// Returns `None` if the cell is empty.
pub(crate) fn get_mut(&mut self) -> Option<&mut T> {
Expand Down
20 changes: 0 additions & 20 deletions src/imp_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,6 @@ impl<T> OnceCell<T> {
}
}

/// Get a mutable reference to the underlying value, without checking if the cell
/// is initialized.
///
/// # Safety
///
/// Caller must ensure that the cell is in initialized state, and that
/// the contents are acquired by (synchronized to) this thread.
pub(crate) unsafe fn get_mut_unchecked(&mut self) -> &mut T {
debug_assert!(self.is_initialized());
let slot: &mut Option<T> = &mut *self.value.get();
match slot {
Some(value) => value,
// This unsafe does improve performance, see `examples/bench`.
None => {
debug_assert!(false);
unreachable_unchecked()
}
}
}

/// Gets the mutable reference to the underlying value.
/// Returns `None` if the cell is empty.
pub(crate) fn get_mut(&mut self) -> Option<&mut T> {
Expand Down
11 changes: 0 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,17 +1095,6 @@ pub mod sync {
self.0.get_unchecked()
}

/// Get a mutable reference to the underlying value, without checking if the
/// cell is initialized.
///
/// # Safety
///
/// Caller must ensure that the cell is in initialized state, and that
/// the contents are acquired by (synchronized to) this thread.
pub unsafe fn get_mut_unchecked(&mut self) -> &mut T {
self.0.get_mut_unchecked()
}

/// Sets the contents of this cell to `value`.
///
/// Returns `Ok(())` if the cell was empty and `Err(value)` if it was
Expand Down
9 changes: 0 additions & 9 deletions tests/it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,6 @@ mod sync {
}
}

#[test]
fn once_cell_get_mut_unchecked() {
let mut c = OnceCell::new();
c.set(92).unwrap();
unsafe {
assert_eq!(c.get_mut_unchecked(), &mut 92);
}
}

#[test]
fn once_cell_drop() {
static DROP_CNT: AtomicUsize = AtomicUsize::new(0);
Expand Down

0 comments on commit 8b19199

Please sign in to comment.