Skip to content

Commit b92f110

Browse files
committed
Deserialize the description info at the beginning
1 parent 88ceb7d commit b92f110

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/bitmap/ops_with_serialized.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use std::ops::RangeInclusive;
88

99
use crate::bitmap::container::Container;
1010
use crate::bitmap::serialization::{
11-
DESCRIPTION_BYTES, NO_OFFSET_THRESHOLD, OFFSET_BYTES, SERIAL_COOKIE,
12-
SERIAL_COOKIE_NO_RUNCONTAINER,
11+
NO_OFFSET_THRESHOLD, OFFSET_BYTES, SERIAL_COOKIE, SERIAL_COOKIE_NO_RUNCONTAINER,
1312
};
1413
use crate::RoaringBitmap;
1514

@@ -94,25 +93,26 @@ impl RoaringBitmap {
9493
}
9594

9695
// Read the container descriptions
97-
let mut description_bytes = vec![0u8; size * DESCRIPTION_BYTES];
98-
reader.read_exact(&mut description_bytes)?;
99-
let mut description_bytes = &description_bytes[..];
96+
let mut description_bytes = vec![[0u16; 2]; size];
97+
reader.read_exact(cast_slice_mut(&mut description_bytes))?;
98+
description_bytes.iter_mut().for_each(|[ref mut key, ref mut len]| {
99+
*key = u16::from_le(*key);
100+
*len = u16::from_le(*len);
101+
});
102+
100103

101104
if has_offsets {
102105
// I could use these offsets but I am a lazy developer (for now)
103106
reader.seek(SeekFrom::Current((size * OFFSET_BYTES) as i64))?;
104107
}
105108

106-
let mut containers = Vec::new();
107-
108109
// Read each container and skip the useless ones
109-
for i in 0..size {
110-
let key = description_bytes.read_u16::<LittleEndian>()?;
110+
for (i, &[key, len_minus_one]) in description_bytes.iter().enumerate() {
111111
let container = match self.containers.binary_search_by_key(&key, |c| c.key) {
112112
Ok(index) => self.containers.get(index),
113113
Err(_) => None,
114114
};
115-
let cardinality = u64::from(description_bytes.read_u16::<LittleEndian>()?) + 1;
115+
let cardinality = u64::from(len_minus_one) + 1;
116116

117117
// If the run container bitmap is present, check if this container is a run container
118118
let is_run_container =

0 commit comments

Comments
 (0)