Skip to content

Commit

Permalink
Do not create extra 0 sized file if last part is bigger than expected.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mgautierfr committed May 2, 2024
1 parent 8097ea4 commit 7dfb05a
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/zimsplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,10 @@ class ZimSplitter
zim::offset_type last(0);
for(auto offset:offsets) {
auto chunkSize = offset-last;

Check warning on line 132 in src/zimsplit.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimsplit.cpp#L132

Added line #L132 was not covered by tests
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;
}
}
Expand Down

0 comments on commit 7dfb05a

Please sign in to comment.