summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-16 11:49:21 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-16 11:49:21 +0100
commitf8aa7d2a399ba7427e22c474191b1bd3331b647c (patch)
tree464432a37e34f39c188aefef690466119288d86e /src
parentfe4cf7b218974a05af58851878ba65d5f0e1f348 (diff)
retrieve file size during dir iteration instead of after opening file
Diffstat (limited to 'src')
-rw-r--r--src/search.cpp20
-rw-r--r--src/search.h1
-rw-r--r--src/unix/main_unix.cpp6
-rw-r--r--src/windows/main_windows.cpp1
4 files changed, 18 insertions, 10 deletions
diff --git a/src/search.cpp b/src/search.cpp
index 5f95e8e..a455630 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -334,19 +334,21 @@ static void *_ts_search_thread(void *args)
new_result->file_list_read_cursor++;
ts_mutex_unlock(&new_result->files.mutex);
- ts_found_file *f = *(ts_found_file **)ts_array_at(&new_result->files, read_cursor);
- ts_file_content content = ts_platform_read_file(f->path, "rb, ccs=UTF-8");
- if (content.file_error != FILE_ERROR_NONE) {
- f->error = content.file_error;
- }
- if (content.content_length > megabytes(new_result->max_file_size)) {
+
+ ts_found_file *f = *(ts_found_file **)ts_array_at(&new_result->files, read_cursor);
+ if (f->file_size > megabytes(new_result->max_file_size)) {
f->error = FILE_ERROR_TOO_BIG;
}
+ else {
+ ts_file_content content = ts_platform_read_file(f->path, "rb, ccs=UTF-8");
+ if (content.file_error != FILE_ERROR_NONE) {
+ f->error = content.file_error;
+ }
- if (f->error == FILE_ERROR_NONE) _ts_search_file(f, content, new_result);
-
- free(content.content);
+ if (f->error == FILE_ERROR_NONE) _ts_search_file(f, content, new_result);
+ free(content.content);
+ }
}
finish_early:
diff --git a/src/search.h b/src/search.h
index 27c7f04..e01aef2 100644
--- a/src/search.h
+++ b/src/search.h
@@ -7,6 +7,7 @@
typedef struct t_ts_found_file
{
utf8_int8_t *path;
+ size_t file_size;
uint32_t match_count;
uint16_t error;
bool collapsed;
diff --git a/src/unix/main_unix.cpp b/src/unix/main_unix.cpp
index 755b617..0c58d02 100644
--- a/src/unix/main_unix.cpp
+++ b/src/unix/main_unix.cpp
@@ -303,10 +303,14 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir)
ts_found_file* f = (ts_found_file*)ts_memory_bucket_reserve(&result->memory, sizeof(ts_found_file));
f->path = (utf8_int8_t*)ts_memory_bucket_reserve(&result->memory, MAX_INPUT_LENGTH);
+ strcpy(f->path, complete_file_path);
f->match_count = 0;
f->error = 0;
f->collapsed = false;
- strcpy(f->path, complete_file_path);
+
+ struct stat file_stat;
+ stat(f->path, &file_stat);
+ f->file_size = file_stat.st_size;
ts_mutex_lock(&result->files.mutex);
ts_array_push_size(&result->files, &f, sizeof(ts_found_file*));
diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp
index 4b086e8..b7f29f7 100644
--- a/src/windows/main_windows.cpp
+++ b/src/windows/main_windows.cpp
@@ -425,6 +425,7 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir)
f->match_count = 0;
f->error = 0;
f->collapsed = false;
+ f->file_size = (file_info.nFileSizeHigh * (MAXDWORD+1)) + file_info.nFileSizeLow;
WideCharToMultiByte(CP_UTF8,0,complete_file_path,-1,(LPSTR)f->path,MAX_INPUT_LENGTH, NULL, NULL);
ts_mutex_lock(&result->files.mutex);