mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 20:55:05 +00:00
misc: drop a few low-hanging unsafes
Remove a couple of unnecessary unsafes: - The NonZeroUsize is a constant where the unwrap will optimize away anyway and we don't have an unsafe without any good reason there :) - The other two were simply not needed, lifetimes worked fine, maybe Rust became better since that code was written? NLL? Anyway, they're gone now
This commit is contained in:
parent
2ac9865ce7
commit
d27351b978
3 changed files with 6 additions and 15 deletions
|
@ -62,8 +62,8 @@ pub fn cmd_run(ui: &mut Ui, command: &CommandHelper, args: &RunArgs) -> Result<(
|
|||
|
||||
// SAFETY:
|
||||
// We use a internal constant of 4 threads, if it fails
|
||||
let available = std::thread::available_parallelism()
|
||||
.unwrap_or(unsafe { NonZeroUsize::new_unchecked(4) });
|
||||
let available =
|
||||
std::thread::available_parallelism().unwrap_or(NonZeroUsize::new(4).unwrap());
|
||||
available.into()
|
||||
};
|
||||
Err(user_error("This is a stub, do not use"))
|
||||
|
|
|
@ -839,11 +839,8 @@ impl<'a> CompositeIndex<'a> {
|
|||
if pos.0 >= num_parent_commits {
|
||||
self.0.segment_entry_by_pos(pos, pos.0 - num_parent_commits)
|
||||
} else {
|
||||
let parent_file: &ReadonlyIndexImpl = self.0.segment_parent_file().unwrap().as_ref();
|
||||
// The parent ReadonlyIndex outlives the child
|
||||
let parent_file: &'a ReadonlyIndexImpl = unsafe { std::mem::transmute(parent_file) };
|
||||
|
||||
CompositeIndex(parent_file).entry_by_pos(pos)
|
||||
let parent_file = self.0.segment_parent_file().unwrap();
|
||||
CompositeIndex(&**parent_file).entry_by_pos(pos)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,14 +51,8 @@ pub trait TableSegment {
|
|||
}
|
||||
|
||||
fn get_value<'a>(&'a self, key: &[u8]) -> Option<&'a [u8]> {
|
||||
if let Some(value) = self.segment_get_value(key) {
|
||||
return Some(value);
|
||||
}
|
||||
let parent_file = self.segment_parent_file()?;
|
||||
let parent_file: &ReadonlyTable = parent_file.as_ref();
|
||||
// The parent ReadonlyIndex outlives the child
|
||||
let parent_file: &'a ReadonlyTable = unsafe { std::mem::transmute(parent_file) };
|
||||
parent_file.get_value(key)
|
||||
self.segment_get_value(key)
|
||||
.or_else(|| self.segment_parent_file()?.get_value(key))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue