From f8aa7d2a399ba7427e22c474191b1bd3331b647c Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 16 Mar 2024 11:49:21 +0100 Subject: retrieve file size during dir iteration instead of after opening file --- src/search.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/search.cpp') 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: -- cgit v1.2.3-70-g09d2