UI/updater: Use 1 MB static memory for hashing

Allocating a vector for the hundreds of small files and only reading
64k at a time was a bottleneck on systems that were not I/O bound.
This commit is contained in:
Richard Stanway 2020-06-14 03:04:29 +02:00
parent 3c91fac18e
commit f03fe34009

View File

@ -45,6 +45,7 @@ void StringToHash(const wchar_t *in, BYTE *out)
bool CalculateFileHash(const wchar_t *path, BYTE *hash)
{
static BYTE hashBuffer[1048576];
blake2b_state blake2;
if (blake2b_init(&blake2, BLAKE2_HASH_LENGTH) != 0)
return false;
@ -54,19 +55,16 @@ bool CalculateFileHash(const wchar_t *path, BYTE *hash)
if (handle == INVALID_HANDLE_VALUE)
return false;
vector<BYTE> buf;
buf.resize(65536);
for (;;) {
DWORD read = 0;
if (!ReadFile(handle, buf.data(), (DWORD)buf.size(), &read,
if (!ReadFile(handle, hashBuffer, sizeof(hashBuffer), &read,
nullptr))
return false;
if (!read)
break;
if (blake2b_update(&blake2, buf.data(), read) != 0)
if (blake2b_update(&blake2, hashBuffer, read) != 0)
return false;
}