Skip to content

Commit 140c922

Browse files
GDScript: Reuse scripts from ResourceCache
1 parent f0aeea2 commit 140c922

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

modules/gdscript/gdscript_cache.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_e
304304
if (singleton->full_gdscript_cache.has(p_path)) {
305305
return singleton->full_gdscript_cache[p_path];
306306
}
307+
// HACK:? Maybe the script should be in `full_gdscript_cache` as well and we only compensate for inconsistencies here.
308+
if (const Ref<GDScript> &ref = ResourceCache::get_ref(p_path); ref.is_valid()) {
309+
return ref;
310+
}
307311
if (singleton->shallow_gdscript_cache.has(p_path)) {
308312
return singleton->shallow_gdscript_cache[p_path];
309313
}
@@ -354,6 +358,15 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro
354358
}
355359
}
356360

361+
// HACK:? Maybe the script should be in `full_gdscript_cache` as well and we only compensate for inconsistencies here.
362+
// If the script is in the `ResourceCache` it should fully loaded: see GH-109345. We check whether there is a shallow script anyway just to be sure.
363+
if (!singleton->shallow_gdscript_cache.has(p_path)) {
364+
script = ResourceCache::get_ref(p_path);
365+
if (script.is_valid() && !p_update_from_disk) {
366+
return script;
367+
}
368+
}
369+
357370
if (script.is_null()) {
358371
script = get_shallow_script(p_path, r_error);
359372
// Only exit early if script failed to load, otherwise let reload report errors.

0 commit comments

Comments
 (0)