Skip to content

Commit

Permalink
Fixed various clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Jan 17, 2024
1 parent 5423bc0 commit e80a94c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Breaking** `async_store_chunk` and `AsyncWritableStorageTraits::set` now take `bytes::Bytes`
- `bytes::Bytes` are used by both supported async stores (`object_store` and `opendal`), and this avoids a copy

### Fixed
- Various clippy warnings

## [0.9.0] - 2024-01-03

### Highlights
Expand Down
8 changes: 4 additions & 4 deletions src/array/codec/array_to_bytes/zfp/zfp_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ZfpField {
} else {
return None;
}
let pointer = data.as_ptr() as *mut std::ffi::c_void;
let pointer = data.as_mut_ptr().cast::<std::ffi::c_void>();
let field = unsafe { zfp_field_1d(pointer, zfp_type_, nx) };
NonNull::new(field).map(Self)
}
Expand All @@ -58,7 +58,7 @@ impl ZfpField {
} else {
return None;
}
let pointer = data.as_ptr() as *mut std::ffi::c_void;
let pointer = data.as_mut_ptr().cast::<std::ffi::c_void>();
let field = unsafe { zfp_field_2d(pointer, zfp_type_, nx, ny) };
NonNull::new(field).map(Self)
}
Expand All @@ -77,7 +77,7 @@ impl ZfpField {
} else {
return None;
}
let pointer = data.as_ptr() as *mut std::ffi::c_void;
let pointer = data.as_mut_ptr().cast::<std::ffi::c_void>();
let field = unsafe { zfp_field_3d(pointer, zfp_type_, nx, ny, nz) };
NonNull::new(field).map(Self)
}
Expand All @@ -97,7 +97,7 @@ impl ZfpField {
} else {
return None;
}
let pointer = data.as_ptr() as *mut std::ffi::c_void;
let pointer = data.as_mut_ptr().cast::<std::ffi::c_void>();
let field = unsafe { zfp_field_4d(pointer, zfp_type_, nx, ny, nz, nw) };
NonNull::new(field).map(Self)
}
Expand Down
2 changes: 1 addition & 1 deletion src/byte_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl ByteRange {

/// Return the internal offset of the byte range (which can be at its start or end).
#[must_use]
pub fn offset(&self) -> u64 {
pub const fn offset(&self) -> u64 {
let (Self::FromStart(offset, _) | Self::FromEnd(offset, _)) = self;
*offset
}
Expand Down
51 changes: 24 additions & 27 deletions src/storage/storage_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,39 +164,36 @@ pub fn store_set_partial_values<T: ReadableWritableStorageTraits>(
key_start_values: &[StoreKeyStartValue],
) -> Result<(), StorageError> {
// Group by key
let group_by_key = key_start_values
key_start_values
.iter()
.group_by(|key_start_value| &key_start_value.key)
.into_iter()
.map(|(key, group)| (key.clone(), group.into_iter().cloned().collect::<Vec<_>>()))
.collect::<Vec<_>>();

// Group by store key
group_by_key.into_iter().try_for_each(|(key, group)| {
// Lock the store key
let mutex = store.mutex(&key)?;
let _lock = mutex.lock();

// Read the store key
let mut bytes = store.get(&key)?.unwrap_or_default();

// Expand the store key if needed
let end_max =
usize::try_from(group.iter().map(StoreKeyStartValue::end).max().unwrap()).unwrap();
if bytes.len() < end_max {
bytes.resize_with(end_max, Default::default);
}
.try_for_each(|(key, group)| {
// Lock the store key
let mutex = store.mutex(&key)?;
let _lock = mutex.lock();

// Read the store key
let mut bytes = store.get(&key)?.unwrap_or_default();

// Expand the store key if needed
let end_max =
usize::try_from(group.iter().map(StoreKeyStartValue::end).max().unwrap()).unwrap();
if bytes.len() < end_max {
bytes.resize_with(end_max, Default::default);
}

// Update the store key
for key_start_value in group {
let start: usize = key_start_value.start.try_into().unwrap();
let end: usize = key_start_value.end().try_into().unwrap();
bytes[start..end].copy_from_slice(key_start_value.value);
}
// Update the store key
for key_start_value in group {
let start: usize = key_start_value.start.try_into().unwrap();
let end: usize = key_start_value.end().try_into().unwrap();
bytes[start..end].copy_from_slice(key_start_value.value);
}

// Write the store key
store.set(&key, &bytes)
})?;
// Write the store key
store.set(&key, &bytes)
})?;
Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/storage/store_lock/store_lock_async/default_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::{

/// Default store mutex guard.
#[derive(Debug)]
#[allow(dead_code)]
pub struct AsyncDefaultStoreMutexGuard<'a>(MutexGuard<'a, ()>);

impl AsyncStoreKeyMutexGuardTraits for AsyncDefaultStoreMutexGuard<'_> {}
Expand Down
1 change: 1 addition & 0 deletions src/storage/store_lock/store_lock_sync/default_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::{

/// Default store mutex guard.
#[derive(Debug)]
#[allow(dead_code)]
pub struct DefaultStoreMutexGuard<'a>(MutexGuard<'a, ()>);

impl StoreKeyMutexGuardTraits for DefaultStoreMutexGuard<'_> {}
Expand Down

0 comments on commit e80a94c

Please sign in to comment.