diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-23 11:07:44 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-23 11:07:44 +0100 |
commit | 37205964b61c4b6d23379a585591009cbddfa6f3 (patch) | |
tree | b72c2ff7cdb811341ea3ac13c277af75e2b2c012 /editor | |
parent | 809bd943948c1f46f3229d8b970ea7e63f6847a6 (diff) | |
parent | 2cfab94fef35245e4ab7ab6f68122b12506701a2 (diff) |
Merge pull request #71441 from KoBeWi/warp_2_scan
Improve performance of imported file scan
Diffstat (limited to 'editor')
-rw-r--r-- | editor/filesystem_dock.cpp | 28 | ||||
-rw-r--r-- | editor/filesystem_dock.h | 2 |
2 files changed, 23 insertions, 7 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 54d5ddacab..a078c58e72 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2941,12 +2941,19 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) { } } -void FileSystemDock::_get_imported_files(const String &p_path, Vector<String> &r_files) const { +bool FileSystemDock::_get_imported_files(const String &p_path, String &r_extension, Vector<String> &r_files) const { if (!p_path.ends_with("/")) { if (FileAccess::exists(p_path + ".import")) { + if (r_extension.is_empty()) { + r_extension = p_path.get_extension(); + } else if (r_extension != p_path.get_extension()) { + r_files.clear(); + return false; // File type mismatch, stop search. + } + r_files.push_back(p_path); } - return; + return true; } Ref<DirAccess> da = DirAccess::open(p_path); @@ -2955,11 +2962,14 @@ void FileSystemDock::_get_imported_files(const String &p_path, Vector<String> &r while (!n.is_empty()) { if (n != "." && n != ".." && !n.ends_with(".import")) { String npath = p_path + n + (da->current_is_dir() ? "/" : ""); - _get_imported_files(npath, r_files); + if (!_get_imported_files(npath, r_extension, r_files)) { + return false; + } } n = da->get_next(); } da->list_dir_end(); + return true; } void FileSystemDock::_update_import_dock() { @@ -2984,10 +2994,16 @@ void FileSystemDock::_update_import_dock() { } } - // Expand directory selection + if (!selected.is_empty() && selected[0] == "res://") { + // Scanning res:// is costly and unlikely to yield any useful results. + return; + } + + // Expand directory selection. Vector<String> efiles; - for (int i = 0; i < selected.size(); i++) { - _get_imported_files(selected[i], efiles); + String extension; + for (const String &fpath : selected) { + _get_imported_files(fpath, extension, efiles); } // Check import. diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 3f12b73043..42a72b7ee8 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -214,7 +214,7 @@ private: void _file_multi_selected(int p_index, bool p_selected); void _tree_multi_selected(Object *p_item, int p_column, bool p_selected); - void _get_imported_files(const String &p_path, Vector<String> &r_files) const; + bool _get_imported_files(const String &p_path, String &r_extension, Vector<String> &r_files) const; void _update_import_dock(); void _get_all_items_in_dir(EditorFileSystemDirectory *p_efsd, Vector<String> &r_files, Vector<String> &r_folders) const; |