| ... | @@ -7,9 +7,6 @@ const Compilation = @import("../../Compilation.zig"); | ... | @@ -7,9 +7,6 @@ const Compilation = @import("../../Compilation.zig"); |
| 7 | const Md5 = std.crypto.hash.Md5; | 7 | const Md5 = std.crypto.hash.Md5; |
| 8 | const Hasher = @import("hasher.zig").ParallelHasher; | 8 | const Hasher = @import("hasher.zig").ParallelHasher; |
| 9 | | 9 | |
| 10 | /// Somewhat random chunk size for MD5 hash calculation. | | |
| 11 | pub const chunk_size = 0x4000; | | |
| 12 | | | |
| 13 | /// Calculates Md5 hash of each chunk in parallel and then hashes all Md5 hashes to produce | 10 | /// Calculates Md5 hash of each chunk in parallel and then hashes all Md5 hashes to produce |
| 14 | /// the final digest. | 11 | /// the final digest. |
| 15 | /// While this is NOT a correct MD5 hash of the contents, this methodology is used by LLVM/LLD | 12 | /// While this is NOT a correct MD5 hash of the contents, this methodology is used by LLVM/LLD |
| ... | @@ -17,6 +14,8 @@ pub const chunk_size = 0x4000; | ... | @@ -17,6 +14,8 @@ pub const chunk_size = 0x4000; |
| 17 | /// TODO LLD also hashes the output filename to disambiguate between same builds with different | 14 | /// TODO LLD also hashes the output filename to disambiguate between same builds with different |
| 18 | /// output files. Should we also do that? | 15 | /// output files. Should we also do that? |
| 19 | pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[Md5.digest_length]u8) !void { | 16 | pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[Md5.digest_length]u8) !void { |
| | 17 | const num_chunks = @intCast(u64, comp.thread_pool.threads.len) * 10; |
| | 18 | const chunk_size = @divTrunc(file_size + num_chunks - 1, num_chunks); |
| 20 | const total_hashes = mem.alignForward(u64, file_size, chunk_size) / chunk_size; | 19 | const total_hashes = mem.alignForward(u64, file_size, chunk_size) / chunk_size; |
| 21 | | 20 | |
| 22 | const hashes = try comp.gpa.alloc([Md5.digest_length]u8, total_hashes); | 21 | const hashes = try comp.gpa.alloc([Md5.digest_length]u8, total_hashes); |