Skip to content

Commit

Permalink
Use crc32() instead of crc32_z()
Browse files Browse the repository at this point in the history
Old zlib does not support crc32_z. The difference between the two is
that crc32() takes an input size as an unsigned int while crc32_z()
takes as size_t. For our use case, size is guranteed to be short, so
crc32() is safe to use.
  • Loading branch information
rui314 committed Aug 8, 2024
1 parent f18d1c1 commit 1d24b70
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion common/crc32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ u32 compute_crc32(u32 crc, u8 *buf, i64 len) {
}

tbb::parallel_for_each(shards.begin(), shards.end(), [](Shard &shard) {
shard.crc = crc32_z(0, shard.buf, shard.len);
shard.crc = crc32(0, shard.buf, shard.len);
});

for (Shard &shard : shards)
Expand Down

3 comments on commit 1d24b70

@Chilledheart
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If shard.len is short enough (less than 1MiB), then why we still need field len in struct Shard to be type i64? I think type i32 should be enough.

@rui314
Copy link
Owner Author

@rui314 rui314 commented on 1d24b70 Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chilledheart
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense. Thanks!

Please sign in to comment.