mirror of
git://git.proxmox.com/git/pxar.git
synced 2024-12-22 21:33:50 +03:00
clippy fixes
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
149f88f3c9
commit
81d500297d
@ -352,8 +352,9 @@ pub struct FileContents<T> {
|
||||
}
|
||||
|
||||
// We lose `Send` via the boxed trait object and don't want to force the trait object to
|
||||
// potentially be more strict than `T`, so we leave it as it is ans implement Send and Sync
|
||||
// potentially be more strict than `T`, so we leave it as it is and implement Send and Sync
|
||||
// depending on T.
|
||||
#[allow(clippy::non_send_fields_in_send_ty)]
|
||||
unsafe impl<T: Send> Send for FileContents<T> {}
|
||||
unsafe impl<T: Sync> Sync for FileContents<T> {}
|
||||
|
||||
|
@ -96,7 +96,7 @@ async fn read_exact_data_at<T>(input: &T, size: usize, offset: u64) -> io::Resul
|
||||
where
|
||||
T: ReadAt,
|
||||
{
|
||||
let mut data = util::vec_new(size);
|
||||
let mut data = unsafe { util::vec_new_uninitialized(size) };
|
||||
read_exact_at(input, &mut data[..], offset).await?;
|
||||
Ok(data)
|
||||
}
|
||||
@ -171,18 +171,12 @@ impl ReadAt for &'_ [u8] {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
struct Caches {
|
||||
/// The goodbye table cache maps goodbye table offsets to cache entries.
|
||||
gbt_cache: Option<Arc<dyn Cache<u64, [GoodbyeItem]> + Send + Sync>>,
|
||||
}
|
||||
|
||||
impl Default for Caches {
|
||||
fn default() -> Self {
|
||||
Self { gbt_cache: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// The random access state machine implementation.
|
||||
pub(crate) struct AccessorImpl<T> {
|
||||
input: T,
|
||||
@ -433,9 +427,9 @@ impl<T: Clone + ReadAt> DirectoryImpl<T> {
|
||||
/// Load the entire goodbye table:
|
||||
async fn load_table(&self) -> io::Result<Arc<[GoodbyeItem]>> {
|
||||
let len = self.len();
|
||||
let mut data = Vec::with_capacity(self.len());
|
||||
let mut data;
|
||||
unsafe {
|
||||
data.set_len(len);
|
||||
data = crate::util::vec_new_uninitialized(self.len());
|
||||
let slice = std::slice::from_raw_parts_mut(
|
||||
data.as_mut_ptr() as *mut u8,
|
||||
len * size_of::<GoodbyeItem>(),
|
||||
@ -906,6 +900,7 @@ pub struct SeqReadAtAdapter<T> {
|
||||
// We lose `Send` via the boxed trait object and don't want to force the trait object to
|
||||
// potentially be more strict than `T`, so we leave it as it is ans implement Send and Sync
|
||||
// depending on T.
|
||||
#[allow(clippy::non_send_fields_in_send_ty)]
|
||||
unsafe impl<T: Send> Send for SeqReadAtAdapter<T> {}
|
||||
unsafe impl<T: Sync> Sync for SeqReadAtAdapter<T> {}
|
||||
|
||||
|
@ -119,7 +119,7 @@ async fn seq_read_exact_data<T>(input: &mut T, size: usize) -> io::Result<Vec<u8
|
||||
where
|
||||
T: SeqRead + ?Sized,
|
||||
{
|
||||
let mut data = util::vec_new(size);
|
||||
let mut data = unsafe { util::vec_new_uninitialized(size) };
|
||||
seq_read_exact(input, &mut data[..]).await?;
|
||||
Ok(data)
|
||||
}
|
||||
|
@ -315,7 +315,9 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
|
||||
state: EncoderState::default(),
|
||||
parent: None,
|
||||
finished: false,
|
||||
file_copy_buffer: Arc::new(Mutex::new(crate::util::vec_new(1024 * 1024))),
|
||||
file_copy_buffer: Arc::new(Mutex::new(unsafe {
|
||||
crate::util::vec_new_uninitialized(1024 * 1024)
|
||||
})),
|
||||
};
|
||||
|
||||
this.encode_metadata(metadata).await?;
|
||||
|
@ -7,6 +7,7 @@ use std::task::{Context, Poll};
|
||||
|
||||
pub const MAX_READ_BUF_LEN: usize = 4 * 1024 * 1024;
|
||||
|
||||
#[allow(clippy::uninit_vec)]
|
||||
pub fn scale_read_buffer(buffer: &mut Vec<u8>, target: usize) {
|
||||
let target = target.min(MAX_READ_BUF_LEN);
|
||||
|
||||
@ -90,12 +91,11 @@ pub fn read_os_string(buffer: &[u8]) -> std::ffi::OsString {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn vec_new(size: usize) -> Vec<u8> {
|
||||
let mut data = Vec::with_capacity(size);
|
||||
pub unsafe fn vec_new_uninitialized<T>(len: usize) -> Vec<T> {
|
||||
unsafe {
|
||||
data.set_len(size);
|
||||
let data = std::alloc::alloc(std::alloc::Layout::array::<T>(len).unwrap());
|
||||
Vec::from_raw_parts(data as *mut T, len, len)
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
pub fn io_err_other<E: std::fmt::Display>(err: E) -> io::Error {
|
||||
|
Loading…
Reference in New Issue
Block a user