@@ -248,11 +248,16 @@ void EditorFileSystem::_first_scan_filesystem() {
248248 ep.step (TTR (" Scanning file structure..." ), 0 , true );
249249 nb_files_total = _scan_new_dir (first_scan_root_dir, d);
250250
251+ // Preloading GDExtensions file extensions to prevent looping on all the resource loaders
252+ // for each files in _first_scan_process_scripts.
253+ List<String> gdextension_extensions;
254+ ResourceLoader::get_recognized_extensions_for_type (" GDExtension" , &gdextension_extensions);
255+
251256 // This loads the global class names from the scripts and ensures that even if the
252257 // global_script_class_cache.cfg was missing or invalid, the global class names are valid in ScriptServer.
253258 // At the same time, to prevent looping multiple times in all files, it looks for extensions.
254259 ep.step (TTR (" Loading global class names..." ), 1 , true );
255- _first_scan_process_scripts (first_scan_root_dir, existing_class_names, extensions);
260+ _first_scan_process_scripts (first_scan_root_dir, gdextension_extensions, existing_class_names, extensions);
256261
257262 // Removing invalid global class to prevent having invalid paths in ScriptServer.
258263 _remove_invalid_global_class_names (existing_class_names);
@@ -276,41 +281,46 @@ void EditorFileSystem::_first_scan_filesystem() {
276281 ep.step (TTR (" Starting file scan..." ), 5 , true );
277282}
278283
279- void EditorFileSystem::_first_scan_process_scripts (const ScannedDirectory *p_scan_dir, HashSet<String> &p_existing_class_names, HashSet<String> &p_extensions) {
284+ void EditorFileSystem::_first_scan_process_scripts (const ScannedDirectory *p_scan_dir, List<String> &p_gdextension_extensions, HashSet<String> &p_existing_class_names, HashSet<String> &p_extensions) {
280285 for (ScannedDirectory *scan_sub_dir : p_scan_dir->subdirs ) {
281- _first_scan_process_scripts (scan_sub_dir, p_existing_class_names, p_extensions);
286+ _first_scan_process_scripts (scan_sub_dir, p_gdextension_extensions, p_existing_class_names, p_extensions);
282287 }
283288
284289 for (const String &scan_file : p_scan_dir->files ) {
285290 // Optimization to skip the ResourceLoader::get_resource_type for files
286291 // that are not scripts. Some loader get_resource_type methods read the file
287292 // which can be very slow on large projects.
288- String ext = scan_file.get_extension ().to_lower ();
293+ const String ext = scan_file.get_extension ().to_lower ();
289294 bool is_script = false ;
290295 for (int i = 0 ; i < ScriptServer::get_language_count (); i++) {
291296 if (ScriptServer::get_language (i)->get_extension () == ext) {
292297 is_script = true ;
293298 break ;
294299 }
295300 }
296- if (! is_script) {
297- continue ; // Not a script.
298- }
301+ if (is_script) {
302+ const String path = p_scan_dir-> full_path . path_join (scan_file);
303+ const String type = ResourceLoader::get_resource_type (path);
299304
300- String path = p_scan_dir->full_path .path_join (scan_file);
301- String type = ResourceLoader::get_resource_type (path);
305+ if (ClassDB::is_parent_class (type, SNAME (" Script" ))) {
306+ String script_class_extends;
307+ String script_class_icon_path;
308+ String script_class_name = _get_global_script_class (type, path, &script_class_extends, &script_class_icon_path);
309+ _register_global_class_script (path, path, type, script_class_name, script_class_extends, script_class_icon_path);
302310
303- if (ClassDB::is_parent_class (type, SNAME ( " Script " ) )) {
304- String script_class_extends ;
305- String script_class_icon_path;
306- String script_class_name = _get_global_script_class (type, path, &script_class_extends, &script_class_icon_path);
307- _register_global_class_script (path, path, type, script_class_name, script_class_extends, script_class_icon_path);
311+ if (!script_class_name. is_empty ( )) {
312+ p_existing_class_names. insert (script_class_name) ;
313+ }
314+ }
315+ }
308316
309- if (!script_class_name.is_empty ()) {
310- p_existing_class_names.insert (script_class_name);
317+ // Check for GDExtensions.
318+ if (p_gdextension_extensions.find (ext)) {
319+ const String path = p_scan_dir->full_path .path_join (scan_file);
320+ const String type = ResourceLoader::get_resource_type (path);
321+ if (type == SNAME (" GDExtension" )) {
322+ p_extensions.insert (path);
311323 }
312- } else if (type == SNAME (" GDExtension" )) {
313- p_extensions.insert (path);
314324 }
315325 }
316326}
0 commit comments