Skip to content

Commit b02a94a

Browse files
authored
Merge pull request #336 from Dr-Emann/fix_clippy_findings_from_new_msrv
fix: clippy findings from updated msrv
2 parents 9c272cb + f8fe950 commit b02a94a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

roaring/src/bitmap/ops_with_serialized.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ impl RoaringBitmap {
7575
let size = ((cookie >> 16) + 1) as usize;
7676
(size, size >= NO_OFFSET_THRESHOLD, true)
7777
} else {
78-
return Err(io::Error::new(io::ErrorKind::Other, "unknown cookie value"));
78+
return Err(io::Error::other("unknown cookie value"));
7979
}
8080
};
8181

8282
// Read the run container bitmap if necessary
8383
let run_container_bitmap = if has_run_containers {
84-
let mut bitmap = vec![0u8; (size + 7) / 8];
84+
let mut bitmap = vec![0u8; size.div_ceil(8)];
8585
reader.read_exact(&mut bitmap)?;
8686
Some(bitmap)
8787
} else {
8888
None
8989
};
9090

9191
if size > u16::MAX as usize + 1 {
92-
return Err(io::Error::new(io::ErrorKind::Other, "size is greater than supported"));
92+
return Err(io::Error::other("size is greater than supported"));
9393
}
9494

9595
// Read the container descriptions
@@ -125,7 +125,7 @@ impl RoaringBitmap {
125125

126126
// If the run container bitmap is present, check if this container is a run container
127127
let is_run_container =
128-
run_container_bitmap.as_ref().map_or(false, |bm| bm[i / 8] & (1 << (i % 8)) != 0);
128+
run_container_bitmap.as_ref().is_some_and(|bm| bm[i / 8] & (1 << (i % 8)) != 0);
129129

130130
let store = if is_run_container {
131131
let runs = reader.read_u16::<LittleEndian>()?;
@@ -232,7 +232,7 @@ impl RoaringBitmap {
232232

233233
// If the run container bitmap is present, check if this container is a run container
234234
let is_run_container =
235-
run_container_bitmap.as_ref().map_or(false, |bm| bm[i / 8] & (1 << (i % 8)) != 0);
235+
run_container_bitmap.as_ref().is_some_and(|bm| bm[i / 8] & (1 << (i % 8)) != 0);
236236

237237
let store = if is_run_container {
238238
let runs = reader.read_u16::<LittleEndian>().unwrap();

roaring/src/bitmap/serialization.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl RoaringBitmap {
8585
let cookie = SERIAL_COOKIE as u32 | ((size as u32 - 1) << 16);
8686
writer.write_u32::<LittleEndian>(cookie)?;
8787
// It is then followed by a bitset indicating which containers are run containers
88-
let run_container_bitmap_size = (size + 7) / 8;
88+
let run_container_bitmap_size = size.div_ceil(8);
8989
let mut run_container_bitmap = vec![0; run_container_bitmap_size];
9090
for (i, container) in self.containers.iter().enumerate() {
9191
if let Store::Run(_) = container.store {
@@ -223,21 +223,21 @@ impl RoaringBitmap {
223223
let size = ((cookie >> 16) + 1) as usize;
224224
(size, size >= NO_OFFSET_THRESHOLD, true)
225225
} else {
226-
return Err(io::Error::new(io::ErrorKind::Other, "unknown cookie value"));
226+
return Err(io::Error::other("unknown cookie value"));
227227
}
228228
};
229229

230230
// Read the run container bitmap if necessary
231231
let run_container_bitmap = if has_run_containers {
232-
let mut bitmap = vec![0u8; (size + 7) / 8];
232+
let mut bitmap = vec![0u8; size.div_ceil(8)];
233233
reader.read_exact(&mut bitmap)?;
234234
Some(bitmap)
235235
} else {
236236
None
237237
};
238238

239239
if size > u16::MAX as usize + 1 {
240-
return Err(io::Error::new(io::ErrorKind::Other, "size is greater than supported"));
240+
return Err(io::Error::other("size is greater than supported"));
241241
}
242242

243243
// Read the container descriptions
@@ -269,7 +269,7 @@ impl RoaringBitmap {
269269

270270
// If the run container bitmap is present, check if this container is a run container
271271
let is_run_container =
272-
run_container_bitmap.as_ref().map_or(false, |bm| bm[i / 8] & (1 << (i % 8)) != 0);
272+
run_container_bitmap.as_ref().is_some_and(|bm| bm[i / 8] & (1 << (i % 8)) != 0);
273273

274274
let store = if is_run_container {
275275
let runs = reader.read_u16::<LittleEndian>()?;
@@ -329,7 +329,7 @@ fn header_size(size: usize, has_run_containers: bool) -> usize {
329329
if has_run_containers {
330330
// New format encodes the size (number of containers) into the 4 byte cookie
331331
// Additionally a bitmap is included marking which containers are run containers
332-
let run_container_bitmap_size = (size + 7) / 8;
332+
let run_container_bitmap_size = size.div_ceil(8);
333333
// New format conditionally includes offsets if there are 4 or more containers
334334
if size >= NO_OFFSET_THRESHOLD {
335335
COOKIE_BYTES + ((DESCRIPTION_BYTES + OFFSET_BYTES) * size) + run_container_bitmap_size

roaring/src/bitmap/store/array_store/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl BitAndAssign<&Self> for ArrayStore {
422422
let mut i = 0;
423423
self.retain(|x| {
424424
i += rhs.iter().skip(i).position(|y| *y >= x).unwrap_or(rhs.vec.len());
425-
rhs.vec.get(i).map_or(false, |y| x == *y)
425+
rhs.vec.get(i).is_some_and(|y| x == *y)
426426
});
427427
}
428428
}

roaring/src/bitmap/store/bitmap_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl BitmapStore {
4040

4141
pub fn from_lsb0_bytes_unchecked(bytes: &[u8], byte_offset: usize, bits_set: u64) -> Self {
4242
const BITMAP_BYTES: usize = BITMAP_LENGTH * size_of::<u64>();
43-
assert!(byte_offset.checked_add(bytes.len()).map_or(false, |sum| sum <= BITMAP_BYTES));
43+
assert!(byte_offset.checked_add(bytes.len()).is_some_and(|sum| sum <= BITMAP_BYTES));
4444

4545
// If we know we're writing the full bitmap, we can avoid the initial memset to 0
4646
let mut bits = if bytes.len() == BITMAP_BYTES {
@@ -68,7 +68,7 @@ impl BitmapStore {
6868
if !cfg!(target_endian = "little") {
6969
// Convert all words we touched (even partially) to little-endian
7070
let start_word = byte_offset / size_of::<u64>();
71-
let end_word = (byte_offset + bytes.len() + (size_of::<u64>() - 1)) / size_of::<u64>();
71+
let end_word = (byte_offset + bytes.len()).div_ceil(size_of::<u64>());
7272

7373
// The 0th byte is the least significant byte, so we've written the bytes in little-endian
7474
for word in &mut bits[start_word..end_word] {

0 commit comments

Comments
 (0)