File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -510,7 +510,11 @@ impl QueueFile {
510510 Ok ( self . inner . file . sync_all ( ) ?)
511511 }
512512
513- fn cache_last_offset_if_needed ( & mut self , count : usize ) {
513+ fn cache_last_offset_if_needed ( & mut self , affected_items : usize ) {
514+ if self . elem_cnt == 0 {
515+ return ;
516+ }
517+
514518 let need_to_cache = self . offset_cache_kind . map_or ( false , |kind| {
515519 let last_index = self . elem_cnt - 1 ;
516520
@@ -521,7 +525,7 @@ impl QueueFile {
521525 }
522526 OffsetCacheKind :: Quadratic => {
523527 let x = ( last_index as f64 ) . sqrt ( ) as usize ;
524- x > 1 && ( self . elem_cnt - count ..=last_index) . contains ( & ( x * x) )
528+ x > 1 && ( self . elem_cnt - affected_items ..=last_index) . contains ( & ( x * x) )
525529 }
526530 }
527531 } ) ;
@@ -1295,7 +1299,7 @@ impl Iter<'_> {
12951299 . wrap_pos ( current. pos + Element :: HEADER_LENGTH as u64 + current. len as u64 ) ;
12961300 self . next_elem_index += 1 ;
12971301
1298- self . queue_file . cache_last_offset_if_needed ( self . next_elem_index ) ;
1302+ self . queue_file . cache_last_offset_if_needed ( 1 ) ;
12991303
13001304 Some ( & self . buffer [ ..current. len ] )
13011305 }
You can’t perform that action at this time.
0 commit comments