提交 f03fe340 编写于 作者: R Richard Stanway

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.
上级 3c91fac1
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册