From b92f110c7363901b2bc170585c4fc7e98538c79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 6 Jun 2024 10:09:03 -0400 Subject: [PATCH] Deserialize the description info at the beginning --- src/bitmap/ops_with_serialized.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bitmap/ops_with_serialized.rs b/src/bitmap/ops_with_serialized.rs index cb27dd45..e9404e9d 100644 --- a/src/bitmap/ops_with_serialized.rs +++ b/src/bitmap/ops_with_serialized.rs @@ -8,8 +8,7 @@ use std::ops::RangeInclusive; use crate::bitmap::container::Container; use crate::bitmap::serialization::{ - DESCRIPTION_BYTES, NO_OFFSET_THRESHOLD, OFFSET_BYTES, SERIAL_COOKIE, - SERIAL_COOKIE_NO_RUNCONTAINER, + NO_OFFSET_THRESHOLD, OFFSET_BYTES, SERIAL_COOKIE, SERIAL_COOKIE_NO_RUNCONTAINER, }; use crate::RoaringBitmap; @@ -94,25 +93,26 @@ impl RoaringBitmap { } // Read the container descriptions - let mut description_bytes = vec![0u8; size * DESCRIPTION_BYTES]; - reader.read_exact(&mut description_bytes)?; - let mut description_bytes = &description_bytes[..]; + let mut description_bytes = vec![[0u16; 2]; size]; + reader.read_exact(cast_slice_mut(&mut description_bytes))?; + description_bytes.iter_mut().for_each(|[ref mut key, ref mut len]| { + *key = u16::from_le(*key); + *len = u16::from_le(*len); + }); + if has_offsets { // I could use these offsets but I am a lazy developer (for now) reader.seek(SeekFrom::Current((size * OFFSET_BYTES) as i64))?; } - let mut containers = Vec::new(); - // Read each container and skip the useless ones - for i in 0..size { - let key = description_bytes.read_u16::()?; + for (i, &[key, len_minus_one]) in description_bytes.iter().enumerate() { let container = match self.containers.binary_search_by_key(&key, |c| c.key) { Ok(index) => self.containers.get(index), Err(_) => None, }; - let cardinality = u64::from(description_bytes.read_u16::()?) + 1; + let cardinality = u64::from(len_minus_one) + 1; // If the run container bitmap is present, check if this container is a run container let is_run_container =