diff --git a/src/sums.d b/src/sums.d index 983b566..788c329 100644 --- a/src/sums.d +++ b/src/sums.d @@ -25,6 +25,8 @@ import std.exception; import std.format; import std.array : appender; +mixin(import("tigersumConfig.d")); + private void writeError (string parFile, string parMessage) { stderr.writefln("tigersum: %s: %s", parFile, parMessage); } @@ -34,6 +36,8 @@ private void writeWarning (string parMessage) { } void calculateSums (in string[] parFiles, in string parCWD, bool parTiger2, string parFileMode, bool parBsdStyle) { + ulong[] read_buff = new ulong[READ_BUFF_BLOCKS * 64 / ulong.sizeof]; + foreach (file_name; parFiles) { const auto curr_path = parCWD ~ file_name; File curr_file; @@ -46,7 +50,7 @@ void calculateSums (in string[] parFiles, in string parCWD, bool parTiger2, stri } if (!isDir(curr_path)) { - const string hash = tigerToString(getTiger(curr_file, parTiger2)); + const string hash = tigerToString(getTiger(curr_file, parTiger2, cast(char[])read_buff)); if (parBsdStyle) { writefln("tiger (%s) = %s", file_name, hash); } diff --git a/src/tiger.d b/src/tiger.d index 18288d5..7825640 100644 --- a/src/tiger.d +++ b/src/tiger.d @@ -49,6 +49,35 @@ public ulong[3] getTiger (in string parData, bool parV2) { return retval; } +public ulong[3] getTiger (ref File parData, bool parV2, char[] parBuffer) { + assert(parBuffer.length == 64 * READ_BUFF_BLOCKS); + assert((cast(size_t)parBuffer.ptr & cast(size_t)(ulong.alignof - 1)) == 0); + + ulong[3] retval; + auto data_left = parData.size; + const auto buff_length = 64 * READ_BUFF_BLOCKS; + + tiger_init(retval); + while (data_left >= buff_length) { + parData.rawRead(parBuffer); + tiger_chunk(parBuffer.ptr, buff_length, retval); + data_left -= buff_length; + } + + const char padding = (parV2 ? 0x80 : 0x01); + if (data_left) { + parData.rawRead(parBuffer[0 .. data_left]); + const ulong proc_length = data_left & ~0x3fUL; + tiger_chunk(parBuffer.ptr, proc_length, retval); + tiger_last_chunk(parBuffer.ptr + proc_length, data_left - proc_length, parData.size, retval, padding); + } + else { + tiger_last_chunk(null, 0, parData.size, retval, padding); + } + + return retval; +} + public ulong[3] getTiger (ref File parData, bool parV2) { const auto buff_length = 64 * READ_BUFF_BLOCKS; char[] unaligned = new char[buff_length + ulong.alignof - 1]; @@ -59,27 +88,7 @@ public ulong[3] getTiger (ref File parData, bool parV2) { char[] aligned = unaligned[offset .. buff_length]; assert(aligned.length == buff_length); - ulong[3] retval; - auto data_left = parData.size; - tiger_init(retval); - while (data_left >= buff_length) { - parData.rawRead(aligned); - tiger_chunk(aligned.ptr, buff_length, retval); - data_left -= buff_length; - } - - const char padding = (parV2 ? 0x80 : 0x01); - if (data_left) { - parData.rawRead(aligned[0 .. data_left]); - const ulong proc_length = data_left & ~0x3fUL; - tiger_chunk(aligned.ptr, proc_length, retval); - tiger_last_chunk(aligned.ptr + proc_length, data_left - proc_length, parData.size, retval, padding); - } - else { - tiger_last_chunk(null, 0, parData.size, retval, padding); - } - - return retval; + return getTiger(parData, parV2, aligned); } public string tigerToString (in ulong[3] parTiger) {