From 22a0cbc07b3509af22bacc7ad04aebbf733aaafd Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Fri, 15 Apr 2022 16:18:09 +0200 Subject: [PATCH] Make handling of very small chunks slightly faster --- src/main.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 43b67bd..3c46d07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,7 @@ fn check_files_to_keep(config: &Config, files: &[FileName]) -> Result Result {start_of_chunk}"); loop { @@ -160,18 +160,24 @@ fn check_files_to_keep(config: &Config, files: &[FileName]) -> Result end_of_chunk { - trace!("{file} is in chunk. beaten by {chunk_file_to_keep:?}"); - chunk_file_to_keep.get_or_insert(file); + if !found_file_for_chunk { + keep_files.insert(file); + found_file_for_chunk = true; + trace!("{file} is in chunk. keeping."); + } else { + trace!("{file} is in chunk. beaten by another file"); + } } else { - trace!("reached end of chunk"); files.push(file); // put the file back in the queue - break; - } - } - if let Some(file) = chunk_file_to_keep { - trace!("keeping files {file}"); - keep_files.insert(file); + if file < period_end { + trace!("reached end of period"); + continue 'period; + } else { + trace!("reached end of chunk"); + break; + } + } } }