diff --git a/bucket_map/src/bucket.rs b/bucket_map/src/bucket.rs index a60de11a56..95520a162e 100644 --- a/bucket_map/src/bucket.rs +++ b/bucket_map/src/bucket.rs @@ -402,8 +402,10 @@ impl<'b, T: Clone + Copy + 'static> Bucket { data_len: usize, ref_count: RefCount, ) -> Result<(), BucketMapError> { + let num_slots = data_len as u64; let best_fit_bucket = MultipleSlots::data_bucket_from_num_slots(data_len as u64); - if self.data.get(best_fit_bucket as usize).is_none() { + let requires_data_bucket = num_slots > 1 || ref_count != 1; + if requires_data_bucket && self.data.get(best_fit_bucket as usize).is_none() { // fail early if the data bucket we need doesn't exist - we don't want the index entry partially allocated return Err(BucketMapError::DataNoSpace((best_fit_bucket, 0))); } @@ -420,8 +422,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket { elem_allocate.init(&mut self.index, key); elem_allocate }; - let num_slots = data_len as u64; - if num_slots <= 1 && ref_count == 1 { + if !requires_data_bucket { // new data stored should be stored in IndexEntry and NOT in data file // new data len is 0 or 1 if let OccupiedEnum::MultipleSlots(multiple_slots) =