Using FindFirstFileA() instead of CreateFileA() to get the file size
Since we already call FindFirstFileA() and it returns the size there is no need to open/close every file to get it's size
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "arena.h"
|
||||
#include "platform.h"
|
||||
|
||||
// ----------------------------- Globals ------------------------------------
|
||||
@@ -201,16 +202,7 @@ void scan_folder_windows_parallel(const char *base, DirQueue *q) {
|
||||
|
||||
platform_get_file_owner(full, fe->owner, sizeof(fe->owner));
|
||||
|
||||
LARGE_INTEGER size;
|
||||
HANDLE hf =
|
||||
CreateFileA(full, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
if (hf != INVALID_HANDLE_VALUE) {
|
||||
if (GetFileSizeEx(hf, &size))
|
||||
fe->size_bytes = (uint64_t)size.QuadPart;
|
||||
CloseHandle(hf);
|
||||
}
|
||||
fe->size_bytes = ((uint64_t)fd.nFileSizeHigh << 32) | fd.nFileSizeLow;
|
||||
|
||||
mpmc_push(&g_file_queue, fe);
|
||||
}
|
||||
@@ -474,7 +466,7 @@ int main(int argc, char **argv) {
|
||||
arena_free(&gp_arena, (u8 **)&buf, len);
|
||||
|
||||
// Add some extra threads to overlap I/O more aggressively
|
||||
u8 num_threads = hw_threads * 2;
|
||||
size_t num_threads = hw_threads * 2;
|
||||
if (num_threads < 2)
|
||||
num_threads = 2;
|
||||
|
||||
@@ -526,7 +518,9 @@ int main(int argc, char **argv) {
|
||||
|
||||
WaitForMultipleObjects((DWORD)scan_threads, scan_tids, TRUE, INFINITE);
|
||||
|
||||
mpmc_producers_finished(&g_file_queue, num_threads);
|
||||
for (size_t i = 0; i < num_threads; i++) {
|
||||
mpmc_push(&g_file_queue, NULL);
|
||||
}
|
||||
|
||||
atomic_store(&g_scan_done, 1);
|
||||
|
||||
@@ -597,7 +591,7 @@ int main(int argc, char **argv) {
|
||||
double total_mb = (double)total_bytes / (1024.0 * 1024.0);
|
||||
double avg_mbps = total_mb / total_seconds;
|
||||
printf("Total: %.2f MB, Average: %.2f MB/s\n", total_mb, avg_mbps);
|
||||
printf(" Total time : %.2f seconds\n", total_seconds);
|
||||
printf(" Total time : %.2f seconds\n\n", total_seconds);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user