File Browser: Avoid filling file cache needlessly on auto-complete
This would iterate over all files and call the sneaky `filelist_file()`, meaning each file would be added to the cache for a minor query. That's plenty of unnecessary work and kinda defeats the purpose of the partial cache design.
This commit is contained in:
@@ -2201,11 +2201,15 @@ int filelist_file_find_id(const FileList *filelist, const ID *id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ID *filelist_entry_get_id(const FileList *filelist, const int index)
|
||||
static FileListInternEntry *filelist_entry_intern_get(const FileList *filelist, const int index)
|
||||
{
|
||||
BLI_assert(index >= 0 && index < filelist->filelist.entries_filtered_num);
|
||||
return filelist->filelist_intern.filtered[index];
|
||||
}
|
||||
|
||||
const FileListInternEntry *intern_entry = filelist->filelist_intern.filtered[index];
|
||||
ID *filelist_entry_get_id(const FileList *filelist, const int index)
|
||||
{
|
||||
const FileListInternEntry *intern_entry = filelist_entry_intern_get(filelist, index);
|
||||
return intern_entry->local_data.id;
|
||||
}
|
||||
|
||||
@@ -2214,6 +2218,12 @@ ID *filelist_file_get_id(const FileDirEntry *file)
|
||||
return file->id;
|
||||
}
|
||||
|
||||
const char *filelist_entry_get_relpath(const struct FileList *filelist, int index)
|
||||
{
|
||||
const FileListInternEntry *intern_entry = filelist_entry_intern_get(filelist, index);
|
||||
return intern_entry->relpath;
|
||||
}
|
||||
|
||||
#define FILE_UID_UNSET 0
|
||||
|
||||
static FileUID filelist_uid_generate(FileList *filelist)
|
||||
|
||||
@@ -144,6 +144,11 @@ struct ID *filelist_file_get_id(const struct FileDirEntry *file);
|
||||
* Same as #filelist_file_get_id(), but gets the file by index (doesn't require the file to be
|
||||
* cached, uses #FileListInternEntry only). */
|
||||
struct ID *filelist_entry_get_id(const struct FileList *filelist, int index);
|
||||
/**
|
||||
* Get the #FileDirEntry.relpath value without requiring the #FileDirEntry to be available (doesn't
|
||||
* require the file to be cached, uses #FileListInternEntry only).
|
||||
*/
|
||||
const char *filelist_entry_get_relpath(const struct FileList *filelist, int index);
|
||||
bool filelist_uid_is_set(const FileUID uid);
|
||||
void filelist_uid_unset(FileUID *r_uid);
|
||||
void filelist_file_cache_slidingwindow_set(struct FileList *filelist, size_t window_size);
|
||||
|
||||
@@ -1194,13 +1194,13 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche
|
||||
* if the user selects a single file by entering the filename
|
||||
*/
|
||||
for (int i = 0; i < n; i++) {
|
||||
FileDirEntry *file = filelist_file(sfile->files, i);
|
||||
const char *relpath = filelist_entry_get_relpath(sfile->files, i);
|
||||
/* Do not check whether file is a file or dir here! Causes: #44243
|
||||
* (we do accept directories at this stage). */
|
||||
if (fnmatch(pattern, file->relpath, 0) == 0) {
|
||||
filelist_entry_select_set(sfile->files, file, FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
|
||||
if (fnmatch(pattern, relpath, 0) == 0) {
|
||||
filelist_entry_select_index_set(sfile->files, i, FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
|
||||
if (!match) {
|
||||
BLI_strncpy(matched_file, file->relpath, FILE_MAX);
|
||||
BLI_strncpy(matched_file, relpath, FILE_MAX);
|
||||
}
|
||||
match++;
|
||||
}
|
||||
@@ -1268,8 +1268,8 @@ int autocomplete_file(struct bContext *C, char *str, void * /*arg_v*/)
|
||||
int nentries = filelist_files_ensure(sfile->files);
|
||||
|
||||
for (int i = 0; i < nentries; i++) {
|
||||
FileDirEntry *file = filelist_file(sfile->files, i);
|
||||
UI_autocomplete_update_name(autocpl, file->relpath);
|
||||
const char *relpath = filelist_entry_get_relpath(sfile->files, i);
|
||||
UI_autocomplete_update_name(autocpl, relpath);
|
||||
}
|
||||
match = UI_autocomplete_end(autocpl, str);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user