From 7dfb05a7435bfc9a2aaa26c5857efb443f199bd4 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 2 May 2024 18:07:35 +0200 Subject: [PATCH] Do not create extra 0 sized file if last part is bigger than expected. We don't need to open a new file just after we copy out our big part. Algorithm is simplified (thanks to @veloman-yunkan): - We better check if current part should be closed at beggining of the loop. - Copy the data in the (potentially new) current part. i- No (not so) special cases. --- src/zimsplit.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/zimsplit.cpp b/src/zimsplit.cpp index f0ee2386..1918a658 100644 --- a/src/zimsplit.cpp +++ b/src/zimsplit.cpp @@ -130,20 +130,10 @@ class ZimSplitter zim::offset_type last(0); for(auto offset:offsets) { auto chunkSize = offset-last; - if (chunkSize > maxPartSize) { - // One part is bigger than what we want :/ - // Still have to write it. - if (currentPartSize) { - new_file(); - } - copy_out(chunkSize); - } else { - if (currentPartSize+chunkSize > maxPartSize) { - // It would be too much to write the current part in the current file. - new_file(); - } - copy_out(chunkSize); + if (currentPartSize > 0 && currentPartSize + chunkSize > maxPartSize) { + new_file(); } + copy_out(chunkSize); last = offset; } }